vue-ueditor-wrap 中获取光标所在的位置,插入文本内容

11 篇文章 0 订阅
4 篇文章 1 订阅
1.背景

因项目需要,在富文本编辑框中可以设置样式,并且可以在内容光标所在的位置插入文本内容。

2.项目中使用 vue-ueditor-wrap 请跳转至以下链接进行查看
vue项目中使用vue-ueditor-wrap_理想和远方_在路上的博客-CSDN博客
3.获取光标所在的位置,插入文本内容

只有@ready时候获取到的实例才有focus,execCommand的方法

<template>
<el-row>
    <vue-ueditor-wrap v-model="form.content" @ready="ready" :config="config"  ref="editor" style="width:100%;"></vue-ueditor-wrap>
    <el-button @click='insertText'>插入</el-button>
</el-row>
</template>
<script>
import VueUeditorWrap from "vue-ueditor-wrap";
export default {
  components: {
    VueUeditorWrap,
  },
 data() {
    return {
	  ueditor:{},
      config: {
        // 相对路径
        UEDITOR_HOME_URL: "/UEditor/",
        // 编辑器不自动被内容撑高
        autoHeightEnabled: false,
        // 初始容器高度// 初始容器宽度
        initialFrameHeight: 300,
        initialFrameWidth: "100%",
        toolbars: [
          [
            // "fullscreen",
            "source",
            "|",
            "undo",
            "redo",
            "|",
            "bold",
            "italic",
            "underline",
            "fontborder",
            "strikethrough",
            "superscript",
            "subscript",
            "removeformat",
            "formatmatch",
            "blockquote",
            "pasteplain",
            "|",
            "forecolor",
            "backcolor",
            "insertorderedlist",
            "insertunorderedlist",
            "selectall",
            "cleardoc",
            "|",

            "customstyle",
            "paragraph",
            "fontfamily",
            "fontsize",
            "|",
            "justifyleft",
            "justifycenter",
            "justifyright",
            "justifyjustify",
            "|",
            "imagenone",
            "imageleft",
            "imageright",
            "imagecenter",
            "|",
            "simpleupload",
            "insertimage",
            "|",
            "horizontal",
            "date",
            "time",
          ],
        ],
        // 不显示字数
        wordCount: false,
        // 上传图片路径
        serverUrl: 'http://35.201.165.105:8000/controller.php'
        // 自动保存
        enableAutoSave: true,
      },

    }
  }
  methods: {
    ready(instance) {
      this.ueditor = instance;
      console.log("instance", instance);
    },
    insertText(param) {
      this.ueditor.focus(); // 获取光标位置
      this.ueditor.execCommand("inserthtml", "插入内容"); // 插入文本
    },
  }
}
</script>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在使用UEditor插入锚点时遇到问题的原因是由于UEditor的配置文件定义了HTML标签的过滤规则,导致某些属性被过滤掉而无法成功插入锚点。在配置文件,img标签和a标签的白名单并没有achorename属性和name属性。因此,解决这个问题的方法是修改配置文件,将这两个属性添加到相应的白名单。这样就可以自由地插入任何锚点了。以下是修改后的img标签和a标签的白名单: img: {'src': 1, 'width': 1, 'height': 1, 'border': 1, 'alt': 1, 'title': 1, 'style': 1, 'class': 1, 'align': 1, 'achorename': 1}, a: {'href': 1, 'target': 1, 'name': 1, 'style': 1, 'class': 1} 通过这样的配置修改,你就可以成功地在UEditor插入锚点了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [百度编辑器(Ueditor)最新版(1.4.3.3)插入锚点失败原因分析及BUG修复](https://blog.csdn.net/weixin_33836223/article/details/94641552)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [ueditor使用过程的注意事项](https://blog.csdn.net/weixin_39834090/article/details/111729498)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值