码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 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>

  • 相关阅读:
    redisinsight--基础--01--介绍
    掌握C语言文件操作:从入门到精通的完整指南!
    单目标应用:粒子群优化算法(PSO)求解微电网优化MATLAB
    html网页如何获取后台数据库的数据(html + ajax + php + mysql)
    Semantic Kernel 入门系列:🛸LLM降临的时代
    RabbitMQ初步到精通-第四章-RabbitMQ工作模式-SIMPLE
    【数据库】之MYSQL基本语法
    @SneakyThrows注解
    AXI低功耗接口
    C语言实验三 选择结构程序设计
  • 原文地址:https://blog.csdn.net/weixin_38822843/article/details/132834991
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号