zoukankan      html  css  js  c++  java
  • 【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;
    });

    完工

  • 相关阅读:
    HDU.6681.Rikka with Cake(欧拉公式 树状数组)
    Codeforces.449C.Willem, Chtholly and Seniorious(ODT)
    2017-2018 ACM-ICPC, Asia Daejeon Regional Contest (E,G,H,I,K)
    CF GYM.101987A.Circuits(线段树)
    2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)
    220
    219
    218
    217
    216
  • 原文地址:https://www.cnblogs.com/TiestoRay/p/4997195.html
Copyright © 2011-2022 走看看