zoukankan      html  css  js  c++  java
  • 百度UEditor -- ZeroClipboard is not defined

    项目中一直在使用UEditor,风平浪静。

    近期该项目引入了Requirejs,结果发现在有富文本编辑器的页面都会在控制台报出如下异常:

    Uncaught ReferenceError: ZeroClipboard is not defined ueditor.all.min.js:265

    经查看代码后发现 ueditor.../third-party/zeroclipboard/ZeroClipboard.js中 输出方法的地方是酱紫的

    if (typeof define === "function" && define.amd) {
        define(function() {
          return ZeroClipboard;
        });
      } else if (typeof module === "object" && module && typeof module.exports === "object" && module.exports) {
        module.exports = ZeroClipboard;
      } else {
        window.ZeroClipboard = ZeroClipboard;
      }
    

    意思就是说

    • 如果当前页面的模块加载模式是AMD的 则定义模块
    • 如果是CommonJs的,则输出到模块 ZeroClipboard
    • 否则 把  ZeroClipboard 定义为全局变量

    这样 解决方案就有两种。

    ①不适用模块加载模式来使用这个功能

    这样方法需要修改一点源码,把上面这段代码替换成如下代码即可

    if (typeof define === "function" && define.amd) {
        define(function() {
          return ZeroClipboard;
        });
      } else if (typeof module === "object" && module && typeof module.exports === "object" && module.exports) {
        module.exports = ZeroClipboard;
      }
      window.ZeroClipboard = ZeroClipboard;
    

    ②如果不修改源码,就得在模块加载时做处理了

    首先是修改配置

    require.config({
        baseUrl: '',
        paths: {
            ZeroClipboard: "./UEditor.../ZeroClipboard"//主要是加这句话
        }
    });
    

     然后是在调用这个模块并把模块定义到全局变量

    require(['ZeroClipboard'], function (ZeroClipboard) {
        window['ZeroClipboard'] = ZeroClipboard;
    });
    
  • 相关阅读:
    PhpStorm Swoole 和 CI 代码自动补全
    python正则表达式匹配多行
    ES6 Template Strings(转)
    IntelliJ隐藏特定后缀文件
    网络游戏术语(转)
    mac查看当前调用tcp的进程并关闭指定进程
    袭击Mercurial SCM(HG)
    T 泛型转换
    UiAutomator源代码分析之UiAutomatorBridge框架
    ASP.NET MVC 入门8、ModelState与数据验证
  • 原文地址:https://www.cnblogs.com/shifu204/p/6878798.html
Copyright © 2011-2022 走看看