weixin_58412143 2022-10-26 15:33 采纳率: 91.6%
浏览 220
已结题

wangeditor光标乱跑,回车换行又返回来问题

背景: 使用的是父子组件的形式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>
  • 写回答

1条回答 默认 最新

  • weixin_58412143 2022-10-26 16:02
    关注

    问题2解决办法——

              this.$emit('getChange', html.replace(/<.*?>/ig, "")) // 将内容同步到父组件中
    
    评论

报告相同问题?

问题事件

  • 系统已结题 11月3日
  • 创建了问题 10月26日

悬赏问题

  • ¥15 已知平面坐标系(非直角坐标系)内三个点的坐标,反求两坐标轴的夹角
  • ¥15 webots有问题,无响应
  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上