随笔:vue使用wangEditor富文本编辑器不显示的问题

今天来公司,修补上周富文本编辑器无法在项目中现实的问题,其实问题比较简单,由于富文本编辑器是独立插件,所以就想在html中内联js进行初始化,按照wangEditor的说明,在html页面尾部添加了初始化代码。

<script  type="text/javascript">
        const E = window.wangEditor
        const editor1 = new E('#wangEditor1')
        var menus = ['head', 'bold', 'fontSize', 'fontName', 'italic', 'underline', 'strikeThrough',
        'indent', 'lineHeight', 'foreColor', 'backColor', 'link', 'list', 'justify',
        'quote', 'image', 'table', 'code', 'splitLine', 'undo', 'redo',
        ]
        editor1.config.menus = menus

        editor1.config.uploadImgServer = '/iPDMessage/saveImg'

        editor1.config.uploadFileName = 'FileName'
        editor1.config.uploadImgMaxSize = 20 * 1024 * 1024;//设置图片大小为20M
        editor1.config.uploadImgTimeout = 1000000; //图片上传超时限制10s

        editor1.create()
</script>

但是在页面中,没有产生富文本编辑器,查看页面元素可以发现,wangEditor1元素中为空,这是由于项目使用了vue框架,浏览器不会执行内部js代码,因此将初始化代码放置在created函数中即可。

created:function (){

        const E = window.wangEditor
        const editor1 = new E('#wangEditor1')
        var menus = ['head', 'bold', 'fontSize', 'fontName', 'italic', 'underline', 'strikeThrough',
            'indent', 'lineHeight', 'foreColor', 'backColor', 'link', 'list', 'justify',
            'quote', 'image', 'table', 'code', 'splitLine', 'undo', 'redo',
        ]
        editor1.config.menus = menus

        editor1.config.uploadImgServer = '/iPDMessage/saveImg'

        editor1.config.uploadFileName = 'FileName'
        editor1.config.uploadImgMaxSize = 20 * 1024 * 1024;//设置图片大小为20M
        editor1.config.uploadImgTimeout = 1000000; //图片上传超时限制10s

        editor1.create()
    },

尝试使用$(document).ready()来主动激活初始化代码,但是也没有调用成功,感觉是vue的生命周期复写了jQuery的生命周期函数,导致调用失败,这个问题还在研究,待发现问题根源在更新。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值