共计 704 个字符,预计需要花费 2 分钟才能阅读完成。
编辑数据:
1、首先咱们须要定义一个办法 transContent 转换 v -model 中的值,替换以后编辑器返回的数据(带有 html 标签:<p>、<br/> 等标签)
<Editor :id="tinymceId" v-model="myValue" :init="init" :disabled="disabled" />
<script>
import tinymce from 'tinymce'
import 'tinymce/themes/silver'
// 引入 tinymce-vue
import Editor from '@tinymce/tinymce-vue'
...
// 应用组件模式援用
watch: {
// 监听内容变动
value(newValue) {this.myValue = transContent(newValue)
},
myValue(newValue) {this.$emit('input', transContent(newValue))
}
},
2、transContent 办法:
// 转换成一般字符
export function transContent(str) {if (!str) return str
var arr = {
'lt': '<',
'gt': '>',
'nbsp': '','amp':'&','quot':'"'
}
return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function(all, t) {return arr[t]
})
}
3、init 减少配置:forced_root_block: ”,写在配置项最后面
init: {forced_root_block: '', // 革除标签显示}
4、回显胜利:
正文完