账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    ueditor报错Cannot read property 'lang' of undefined
    26
    0

    点击回复按钮实例化编辑器 点击提交再销毁 有时候没问题有时候各种报错 有没有用过的求解答这种大概是什么原因

    Cannot read property 'lang' of undefined
    Cannot read property 'getDom' of undefined
    Cannot read property 'offsetWidth' of undefined
    Cannot read property 'nodeType' of undefined

    相关代码

     $(document).on('click','.answer',function(){
        var parentClass = $(this).parent().attr('class');
        if($("#replay1").length > 0){
            $('#txtanswer').remove();
            UE.getEditor('replay1').destroy();
        }
        if(parentClass == 'opera'){
          $(this).parent().parent().append(`
            <div id="txtanswer">
              <script id="replay1" name="content" type="text/plain"></script>
              <button class="answerpush">回复</button></div>`)
        }else{
            $(this).parent().parent().parent().parent().append('<div id="txtanswer" class="lithfu"><script id="replay1" name="content" type="text/plain"></script><button class="answerpush">回复</button></div>')
        }
    
        ue1 = UE.getEditor('replay1',{
          toolbars: [
                [ 'emotion']
            ]
       });
    });
    $(document).on('click','.answerpush',function(){
        var html = ue1.getContent();
        var txt = ue1.getContentTxt();
        $('#txtanswer').remove();
        UE.getEditor('replay1').destroy();
    
    })
    
    

    你期待的结果是什么?实际看到的错误信息又是什么?

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • 旧城┐ 普通会员 1楼

      这个错误通常出现在尝试访问未定义的对象的lang属性上。在使用ueditor编辑器时,lang属性通常用于设置编辑器的语言,例如中文、英文等。如果在编辑器初始化时未定义这个属性,那么就会出现这个错误。

      以下是一些可能的解决方案:

      1. 首先,确保在编辑器初始化时已经定义了lang属性。如果你使用的是vue,那么你需要在<template>标签中添加以下代码:

      html <ueditor v-model="editorLang" :lang="editorLang"></ueditor>

      1. 如果你使用的是typescript,那么你需要在on ready钩子中添加以下代码:

      typescript onReady() { this.$refs.ueditor.init(); }

      1. 如果你使用的是webpack,那么你需要在scripts文件中添加以下代码:

      ```javascript import Vue from 'vue'; import UEDitor from 'ueditor';

      Vue.use(UEEditor);

      export default { name: 'app', components: { UEDitor } }; ```

      1. 如果你使用的是浏览器插件,那么你需要在插件初始化时定义lang属性:

      ```javascript import UEDitor from 'ueditor';

      export default { install: function(Vue) { Vue.use(UEEditor);

      Vue.prototype.$ueditor = new UEDitor({
        // 设置编辑器的语言
        lang: 'zh-cn'
      });
      

      } }; ```

      希望这些解决方案对你有所帮助!

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部