1. 程式人生 > >Vue中如何引入CKeditor 文字編輯器

Vue中如何引入CKeditor 文字編輯器

1、下載編輯器包:https://www.npmjs.com/package/ckeditor

2、放到靜態資源目錄中


 在index.html中引入檔案ckeditor.js

<script src='static/ckeditor/ckeditor.js' type="text/javascript"></script>


3、配置webpack檔案配置  build/webpack.base.conf.js

module.exports = {

 externals: {
    "CKEDITOR": "window.CKEDITOR"
  },

}

4、使用

<textarea id="editor" rows="10" cols="80"></textarea>

js中需要引入,生命週期中mounted需要引入如下程式碼

import CKEDITOR from 'CKEDITOR';

mounted() {
  CKEDITOR.replace('editor', {height: '400px', width: '100%', toolbar: 'toolbar_Full'});
  this.editor = CKEDITOR.instances.editor;
}