鍍金池/ 問(wèn)答/網(wǎng)絡(luò)安全  HTML/ vue組件初始化給tinymce設(shè)置內(nèi)容報(bào)錯(cuò)

vue組件初始化給tinymce設(shè)置內(nèi)容報(bào)錯(cuò)

問(wèn)題描述

vue組件初始化給tinymce設(shè)置內(nèi)容報(bào)錯(cuò)

問(wèn)題出現(xiàn)的環(huán)境背景及自己嘗試過(guò)哪些方法

設(shè)置定時(shí)器,可解決。

    setTimeout(() => {
        tinymce.activeEditor.setContent("內(nèi)容")
    }, 1000);

相關(guān)代碼

tinymce.init({
        selector: '#articleEditor',
        branding: false,
        elementpath: false,
        height: 600,
        language: 'zh_CN.GB2312',
        menubar: 'edit insert view format table tools',
        theme: 'modern',
        plugins: [
            'advlist autolink lists link image charmap print preview hr anchor pagebreak imagetools',
            'searchreplace visualblocks visualchars code fullscreen fullpage',
            'insertdatetime media nonbreaking save table contextmenu directionality',
            'emoticons paste textcolor colorpicker textpattern imagetools codesample'
        ],
        toolbar1: ' newnote print fullscreen preview | undo redo | insert | styleselect | forecolor backcolor bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image emoticons media codesample',
        autosave_interval: '20s',
        image_advtab: true,
        table_default_styles: {
            width: '100%',
            borderCollapse: 'collapse'
        }
    });
    
    // 如果沒(méi)有定時(shí)器 || 定時(shí)器時(shí)間低于500ms(視電腦硬件配置及代碼量),會(huì)出現(xiàn)報(bào)錯(cuò)
    setTimeout(() => {
         tinymce.activeEditor.setContent(this.articleContent.content)
    }, 1000);

你期待的結(jié)果是什么?實(shí)際看到的錯(cuò)誤信息又是什么?

如果不設(shè)置定時(shí)器,會(huì)報(bào)錯(cuò)
錯(cuò)誤代碼如下

[Vue warn]: Error in mounted hook: "TypeError: Cannot read property 'parse' of undefined"
回答
編輯回答
奧特蛋

tinymce支持Promise,所以可以在init完成后,利用回調(diào)函數(shù),完成操作

tinymce.init({
       // config
}).then( resolve=>{
        // init完成后,回調(diào)
        // doSomething
})
2017年9月25日 20:52
編輯回答
半心人
tinymce.init({
  selector: 'textarea',
  setup: function (editor) {
    editor.on('init', function (e) {
      console.log('初始化完成');
    });
  }
});

因?yàn)檫€沒(méi)init完成,寫著這個(gè)里面

2017年8月12日 20:00