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

10 篇文章 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
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值