背景: 使用的是父子组件的形式wangeditor富文本作为聊天输入框
情况; 在输入内容时按下alt+回车=换行,
问题1: 换行后光标回到了文本的最后
效果:
<p>dd</p><br/><p>2</p>
我觉得应该是类似这样的;
dd
2
问题2: 怎么把上面这种标签去掉?
父组件——
<Editor :contxt="content" class="editor_css" @getChange="getChange" @keydown.enter.native="keyDown"/>
getChange(html) {
this.content = html
}
子组件——
<template>
<div id="box" class="editor" />
</template>
<script>
import { upload, uploads } from '@/api/public'
import { Loading } from 'element-ui'
import E from 'wangeditor'
export default {
name: 'Editor',
// 接收父组件的传值
props: {
value: { // 输入的内容
type: String,
default: ''
},
isClear: { // 是否清空
type: Boolean,
default: false
},
// 编辑时回显的内容
contxt: {
type: String,
default: ''
},
},
data() {
return {}
},
watch: {
contxt(contxt) {
// console.log(contxt)
// 在这里监听,如果说回显时,把回显的内容放到编辑区域
if (contxt !== '' && contxt !== null) {
this.editor.txt.text(this.contxt)
} else {
this.editor.txt.text('')
}
},
isClear(val) {
// 触发清除
if (val) {
this.editor.txt.clear()
this.info_ = null
}
},
value: function(value) {
// 当内容发生变化是
if (value !== this.editor.txt.html()) {
this.editor.txt.html(this.value)
}
}
},
created() {},
mounted() {
this.initE()
},
methods: {
initE() {
this.editor = new E('#box')
this.editor.config.menus = [.
'emoticon', // 表情
'image' // 插入图片
]
// 在输入内容时,把内容传给父组件
this.editor.config.onchange = (html) => {
this.$emit('getChange', html) // 将内容同步到父组件中
}
this.editor.create()
}
}
}
</script>