修改富文本编辑器绑定值方式,使用:value,手动修改内容时调用组件的setHtml方法

This commit is contained in:
zhigang.li 2018-08-27 14:32:11 +08:00
parent 260c0e3f7b
commit 42fd083f31
3 changed files with 16 additions and 5 deletions

View File

@ -45,6 +45,11 @@ export default {
return `editor${this._uid}`
}
},
methods: {
setHtml (val) {
this.editor.txt.html(val)
}
},
mounted () {
this.editor = new Editor(`#${this.editorId}`)
this.editor.customConfig.onchange = (html) => {
@ -57,7 +62,7 @@ export default {
// create
this.editor.create()
//
let html = localStorage.editorCache
let html = this.value || localStorage.editorCache
if (html) this.editor.txt.html(html)
}
}

View File

@ -293,7 +293,8 @@ export default [
name: 'params',
meta: {
icon: 'md-flower',
title: '动态路由'
title: '动态路由',
notCache: true
},
component: () => import('@/view/argu-page/params.vue')
},
@ -302,7 +303,8 @@ export default [
name: 'query',
meta: {
icon: 'md-flower',
title: '带参路由'
title: '带参路由',
notCache: true
},
component: () => import('@/view/argu-page/query.vue')
}

View File

@ -1,6 +1,7 @@
<template>
<div>
<editor v-model="content" @on-change="handleChange"/>
<editor ref="editor" :value="content" @on-change="handleChange"/>
<button @click="changeContent">修改编辑器内容</button>
</div>
</template>
@ -13,12 +14,15 @@ export default {
},
data () {
return {
content: ''
content: '12312323'
}
},
methods: {
handleChange (html, text) {
console.log(html, text)
},
changeContent () {
this.$refs.editor.setHtml('<p>powered by wangeditor</p>')
}
}
}