vue2.0项目中使用Ueditor富文本编辑器应用中出现的问题
1、如何設置config中的內容
readonly:true,//只讀模式wordCount:false,//是否開啟字數統計
enableAutoSave: false,//自動保存功能
重點:enableAutoSave不一定生效,怎么辦?
ueditor.config.js文件中設置enableAutoSave參數為false就可以關閉本地保存功能。
?//啟用自動保存
?,enableAutoSave: false
ueditor1.4.3版本是沒有效果的,需要修改代碼,在ueditor1.5.0版本已經得到修復。
修改方法
ueditor.all.js文件
找到
// plugins/autosave.js
UE.plugin.register('autosave', function (){
??? var me = this,
??????? //無限循環保護
??????? lastSaveTime = new Date(),
??????? //最小保存間隔時間
??????? MIN_TIME = 20,
??????? //auto save key
??????? saveKey = null;
??? function save ( editor ) {
??????? var saveData;
??????? if ( new Date() – lastSaveTime < MIN_TIME ) {
??????????? return;
??????? }
??????? if ( !editor.hasContents() ) {
??????????? //這里不能調用命令來刪除, 會造成事件死循環
??????????? saveKey && me.removePreferences( saveKey );
??????????? return;
??????? }
??????? lastSaveTime = new Date();
??????? editor._saveFlag = null;
??????? saveData = me.body.innerHTML;
??????? if ( editor.fireEvent( "beforeautosave", {
??????????? content: saveData
??????? } ) === false ) {
??????????? return;
??????? }
??????? me.setPreferences( saveKey, saveData );
??????? editor.fireEvent( "afterautosave", {
??????????? content: saveData
??????? } );
??? }
??? return {
??????? defaultOptions: {
??????????? //默認間隔時間
??????????? saveInterval: 500
??????? },
??????? bindEvents:{
??????????? 'ready':function(){
??????????????? var _suffix = "-drafts-data",
??????????????????? key = null;
??????????????? if ( me.key ) {
??????????????????? key = me.key + _suffix;
??????????????? } else {
??????????????????? key = ( me.container.parentNode.id || 'ue-common' ) + _suffix;
??????????????? }
??????????????? //頁面地址+編輯器ID?保持唯一
??????????????? saveKey = ( location.protocol + location.host + location.pathname ).replace( /[.:\/]/g, '_' ) + key;
??????????? },
??????????? 'contentchange': function () {
?? ????????????//新增加的代碼
??????????????? if (!me.getOpt('enableAutoSave')) {
??????????????????? return;
??????????????? }
??????????????? if ( !saveKey ) {
??????????????????? return;
??????????????? }
??????????????? if ( me._saveFlag ) {
??????????????????? window.clearTimeout( me._saveFlag );
??????????????? }
??????????????? if ( me.options.saveInterval > 0 ) {
??????????????????? me._saveFlag = window.setTimeout( function () {
??????????????????????? save( me );
??????????????????? }, me.options.saveInterval );
??????????????? } else {
??????????????????? save(me);
??????????????? }
??????????? }
??????? },
??????? commands:{
??????????? 'clearlocaldata':{
??????????????? execCommand:function (cmd, name) {
??????????????????? if ( saveKey && me.getPreferences( saveKey ) ) {
??????????????????????? me.removePreferences( saveKey )
??????????????????? }
??????????????? },
??????????????? notNeedUndo: true,
??????????????? ignoreContentChange:true
??????????? },
??????????? 'getlocaldata':{
??????????????? execCommand:function (cmd, name) {
??????????????????? return saveKey ? me.getPreferences( saveKey ) || '' : '';
??????????????? },
??????????????? notNeedUndo: true,
??????????????? ignoreContentChange:true
??????????? },
??????????? 'drafts':{
??????????????? execCommand:function (cmd, name) {
??????????????????? if ( saveKey ) {
??????????????????????? me.body.innerHTML = me.getPreferences( saveKey ) || '<p>'+domUtils.fillHtml+'</p>';
??????????????????????? me.focus(true);
??????????????????? }
??????????????? },
??????????????? queryCommandState: function () {
??????????????????? return saveKey ? ( me.getPreferences( saveKey ) === null ? -1 : 0 ) : -1;
??????????????? },
??????????????? notNeedUndo: true,
??????????????? ignoreContentChange:true
??????????? }
??????? }
??? }
});
以下是新增加的代碼
if (!me.getOpt('enableAutoSave')) {
??? return;
}
ueditor1.4.3版本自動保存關閉不了
https://github.com/fex-team/ueditor/issues/470
已在1.5.0分支修改
https://github.com/fex-team/ueditor/blob/dev-1.5.0/_src/plugins/autosave.js#L71-73
轉載于:https://www.cnblogs.com/warter00774/p/8665135.html
總結
以上是生活随笔為你收集整理的vue2.0项目中使用Ueditor富文本编辑器应用中出现的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Unity中的值传递与引用传递
- 下一篇: jvm内存分配解释