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

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

問題描述

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

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

設(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'
        }
    });
    
    // 如果沒有定時器 || 定時器時間低于500ms(視電腦硬件配置及代碼量),會出現(xiàn)報錯
    setTimeout(() => {
         tinymce.activeEditor.setContent(this.articleContent.content)
    }, 1000);

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

如果不設(shè)置定時器,會報錯
錯誤代碼如下

[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('初始化完成');
    });
  }
});

因為還沒init完成,寫著這個里面

2017年8月12日 20:00