• vue中使用wangEditor以及设置菜单栏


    首先安装,我最开始是安装wangEditor v5版本的也就是安装方式是下面两个

    npm install @wangeditor/editor-for-vue --save
    npm install @wangeditor/editor --save

     但是最后跟着官网的视频教程安装好了,不能够运行,提示是:Module parse failed: Unexpected token (18:966)
    You may need an appropriate loader to handle this file type.
    |  * @param {object} options with values that will be used to replace placeholders
    |  * @returns {any[]} interpolated

    大概就是说我的加载器不能够解析最新的包里面的原码,然后我找了挺久的解决方式,最后当然是没有解决。。。。。。。。。。。

    最后我还是安装了老版本的

     

     首先:npm install wangeditor -sava;

    其次:引入这个包:import E from 'wangeditor'

    在scrip标签中使用mounted钩子创建实例对象

    this.editor = new E('#main')

        this.editor.create()

    然后就可以愉快的使用啦

     如果你想要改变设置栏,你就可以拿到这个对象 this.editor.config,对象里面的menus属性就是对应设置栏,你可以 this.editor.config.menus = ['key', 'head', 'link', 'italic', 'underline']

    设置设置栏只有这5个功能。

    但是要注意把这行代码放在this.editor.create()之前执行

     console.log(this.editor.config.menus)打印结果:

     原本里面是有24个功能的,但是有些用不到,你就可以根据自己的需求该=改

     

     

    呈现效果:

     

    完整代码:

    1. <template>
    2. <div id="main">
    3. <p>你好啊p>
    4. div>
    5. template>
    6. <script>
    7. import E from 'wangeditor'
    8. // const toolbar=DomEditor.getToolbar(this.editor)
    9. export default {
    10. data () {
    11. return {
    12. editor: ''
    13. }
    14. },
    15. components: {},
    16. mounted () {
    17. this.editor = new E('#main')
    18. this.editor.config.menus = ['key', 'head', 'link', 'italic', 'underline']
    19. this.editor.create()
    20. console.log('@', this.editor)
    21. console.log(this.editor.config.menus)
    22. }
    23. }
    24. script>
    25. <style>
    26. style>

     

  • 相关阅读:
    MongoDB聚合运算符:$denseRank
    spring boot整合 Redis
    Qt应用开发(基础篇)——复选按钮 QCheckBox 单选按钮 QRadioButton
    ICMP差错包
    会声会影下载要钱吗?会声会影2023中文旗舰版下载
    Linux环境下C++ 接入OpenSSL
    力扣(LeetCode)272. 最接近的二叉搜索树值 II(2022.09.29)
    一行日志,让整个文件导出服务导出内容都为空..
    centos7安装mysql8.0
    【微服务】SpringCloud中OpenFeign请求处理及负载均衡流程
  • 原文地址:https://blog.csdn.net/qq_51580852/article/details/126004183