fix:fix tinymce bug in <keep-alive>

This commit is contained in:
Pan 2017-10-31 11:06:41 +08:00
parent 1ae31fdd45
commit 2c868f47d9
1 changed files with 44 additions and 65 deletions

View File

@ -52,36 +52,45 @@ export default {
} }
}, },
mounted() { mounted() {
const _this = this this.initTinymce()
window.tinymce.init({ },
selector: `#${this.tinymceId}`, activated() {
height: this.height, this.initTinymce()
body_class: 'panel-body ', },
object_resizing: false, deactivated() {
toolbar: this.toolbar, this.destroyTinymce()
menubar: this.menubar, },
plugins: 'advlist,autolink,code,paste,textcolor, colorpicker,fullscreen,link,lists,media,wordcount, imagetools', methods: {
end_container_on_empty_block: true, initTinymce() {
powerpaste_word_import: 'clean', const _this = this
code_dialog_height: 450, window.tinymce.init({
code_dialog_width: 1000, selector: `#${this.tinymceId}`,
advlist_bullet_styles: 'square', height: this.height,
advlist_number_styles: 'default', body_class: 'panel-body ',
block_formats: '普通标签=p;小标题=h2;', object_resizing: false,
imagetools_cors_hosts: ['wpimg.wallstcn.com', 'wallstreetcn.com'], toolbar: this.toolbar,
imagetools_toolbar: 'watermark', menubar: this.menubar,
default_link_target: '_blank', plugins: 'advlist,autolink,code,paste,textcolor, colorpicker,fullscreen,link,lists,media,wordcount, imagetools',
link_title: false, end_container_on_empty_block: true,
init_instance_callback: editor => { powerpaste_word_import: 'clean',
if (_this.value) { code_dialog_height: 450,
editor.setContent(_this.value) code_dialog_width: 1000,
advlist_bullet_styles: 'square',
advlist_number_styles: 'default',
imagetools_cors_hosts: ['wpimg.wallstcn.com', 'wallstreetcn.com'],
imagetools_toolbar: 'watermark',
default_link_target: '_blank',
link_title: false,
init_instance_callback: editor => {
if (_this.value) {
editor.setContent(_this.value)
}
_this.hasInit = true
editor.on('NodeChange Change KeyUp', () => {
this.hasChange = true
this.$emit('input', editor.getContent({ format: 'raw' }))
})
} }
_this.hasInit = true
editor.on('NodeChange Change KeyUp', () => {
this.hasChange = true
this.$emit('input', editor.getContent({ format: 'raw' }))
})
},
// //
// images_dataimg_filter(img) { // images_dataimg_filter(img) {
// setTimeout(() => { // setTimeout(() => {
@ -115,41 +124,11 @@ export default {
// console.log(err); // console.log(err);
// }); // });
// }, // },
setup(editor) { })
editor.addButton('h2', { },
title: '小标题', // tooltip text seen on mouseover destroyTinymce() {
text: '小标题', window.tinymce.get(this.tinymceId).destroy()
onclick() { },
editor.execCommand('mceToggleFormat', false, 'h2')
},
onPostRender() {
const btn = this
editor.on('init', () => {
editor.formatter.formatChanged('h2', state => {
btn.active(state)
})
})
}
})
editor.addButton('p', {
title: '正文',
text: '正文',
onclick() {
editor.execCommand('mceToggleFormat', false, 'p')
},
onPostRender() {
const btn = this
editor.on('init', () => {
editor.formatter.formatChanged('p', state => {
btn.active(state)
})
})
}
})
}
})
},
methods: {
setContent(value) { setContent(value) {
window.tinymce.get(this.tinymceId).setContent(value) window.tinymce.get(this.tinymceId).setContent(value)
}, },
@ -164,7 +143,7 @@ export default {
} }
}, },
destroyed() { destroyed() {
window.tinymce.get(this.tinymceId).destroy() this.destroyTinymce()
} }
} }
</script> </script>