码农知识堂 - 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>

  • 相关阅读:
    游戏中有n条龙,每条龙都有自身力量x及战胜它后的奖励力量 y,当你的力量超过龙时,才能打败龙和获得奖励力量。你可以自由选择挑战顺序,问最后你最多能打败多少条龙?
    广东海洋大学计算机考研资料汇总
    在 Azure ML 上用 .NET 跑机器学习
    ICEM使用经验与网格划分错误分析
    互联网摸鱼日报(2022-11-29)
    Java面试题(每天10题)-------连载(32)
    基于B/S机场飞机票网上订票管理系统【Java毕业设计·安装调试·代码讲解·文档报告】
    BigDecimal在生产上怎么用?
    LeetCode 210. 课程表 II(拓扑排序)
    边缘检测算法
  • 原文地址:https://blog.csdn.net/weixin_38822843/article/details/132834991
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号