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


    1.背景

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

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

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

    1. <template>
    2. <el-row>
    3. <vue-ueditor-wrap v-model="form.content" @ready="ready" :config="config" ref="editor" style="width:100%;">vue-ueditor-wrap>
    4. <el-button @click='insertText'>插入el-button>
    5. el-row>
    6. template>
    7. <script>
    8. import VueUeditorWrap from "vue-ueditor-wrap";
    9. export default {
    10. components: {
    11. VueUeditorWrap,
    12. },
    13. data() {
    14. return {
    15. ueditor:{},
    16. config: {
    17. // 相对路径
    18. UEDITOR_HOME_URL: "/UEditor/",
    19. // 编辑器不自动被内容撑高
    20. autoHeightEnabled: false,
    21. // 初始容器高度// 初始容器宽度
    22. initialFrameHeight: 300,
    23. initialFrameWidth: "100%",
    24. toolbars: [
    25. [
    26. // "fullscreen",
    27. "source",
    28. "|",
    29. "undo",
    30. "redo",
    31. "|",
    32. "bold",
    33. "italic",
    34. "underline",
    35. "fontborder",
    36. "strikethrough",
    37. "superscript",
    38. "subscript",
    39. "removeformat",
    40. "formatmatch",
    41. "blockquote",
    42. "pasteplain",
    43. "|",
    44. "forecolor",
    45. "backcolor",
    46. "insertorderedlist",
    47. "insertunorderedlist",
    48. "selectall",
    49. "cleardoc",
    50. "|",
    51. "customstyle",
    52. "paragraph",
    53. "fontfamily",
    54. "fontsize",
    55. "|",
    56. "justifyleft",
    57. "justifycenter",
    58. "justifyright",
    59. "justifyjustify",
    60. "|",
    61. "imagenone",
    62. "imageleft",
    63. "imageright",
    64. "imagecenter",
    65. "|",
    66. "simpleupload",
    67. "insertimage",
    68. "|",
    69. "horizontal",
    70. "date",
    71. "time",
    72. ],
    73. ],
    74. // 不显示字数
    75. wordCount: false,
    76. // 上传图片路径
    77. serverUrl: 'http://35.201.165.105:8000/controller.php'
    78. // 自动保存
    79. enableAutoSave: true,
    80. },
    81. }
    82. }
    83. methods: {
    84. ready(instance) {
    85. this.ueditor = instance;
    86. console.log("instance", instance);
    87. },
    88. insertText(param) {
    89. this.ueditor.focus(); // 获取光标位置
    90. this.ueditor.execCommand("inserthtml", "插入内容"); // 插入文本
    91. },
    92. }
    93. }
    94. script>

  • 相关阅读:
    mysql 主从复制的延迟问题
    【754. 到达终点数字】
    设计模式(1)-设计模式前置基础知识
    北工大汇编——综合题(1)
    撞上元宇宙冷门新职业 我变年入百万打工人
    基于Python3搭建qt开发环境
    Docker容器-Consul部署
    react 使用 valtio
    使用 PyTorch 的计算机视觉简介 (1/6)
    【SQL】优化SQL查询方法
  • 原文地址:https://blog.csdn.net/weixin_38822843/article/details/132834991