Skip to content

Instantly share code, notes, and snippets.

@erguotou520
Created November 10, 2016 09:50
Show Gist options
  • Save erguotou520/003b50961b426a99c45607b2ca7ab7fd to your computer and use it in GitHub Desktop.
Save erguotou520/003b50961b426a99c45607b2ca7ab7fd to your computer and use it in GitHub Desktop.
<template>
<div ref="editor" :style="{height:height}"><slot></slot></div>
</template>
<script>
const WangEditor = require('wangeditor')
export default {
props: {
value: String,
height: {
type: String,
default: '14rem'
}
},
data () {
return {
editor: null
}
},
mounted () {
const editor = new WangEditor(this.$refs.editor)
editor.config.menus = [
'bold',
'underline',
'italic',
'strikethrough',
'eraser',
'forecolor',
'bgcolor',
'|',
'quote',
'fontfamily',
'fontsize',
'head',
'unorderlist',
'orderlist',
'alignleft',
'aligncenter',
'alignright',
'|',
'link',
'unlink',
'table',
'|',
'img',
'video',
'|',
'undo',
'redo',
'fullscreen'
]
editor.onchange = () => {
this.$emit('input', editor.$txt.html())
}
if (!this.$slots.default && this.value) {
editor.txt.$txt.html(this.value)
}
editor.create()
this.editor = editor
},
beforeDestroy () {
this.editor.destroy()
}
}
</script>
@tangdw
Copy link

tangdw commented Dec 2, 2016

mounted钩子里,涉及实体dom的代码,建议放在
this.$nextTick(() => {
// ...
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment