【js】require.js让jquery不出现在全局变量上

解决

  1. 在main.js文件里定义
requirejs.config({
    paths: {

        jquery: 'jquery.min'
    },

    map: {
        '*': {
            'jquery': 'jquery-private'
        },

        'jquery-private': {
            'jquery': 'jquery'
        }
    }
})
  1. 在js目录下新建一个 jquery-private.js 文件
define(['jquery'], function(jq) {

    return jq.noConflict(true)
});
  1. 回到main.js,在require.config之后,正常调用就行
require(['jquery'], function ($) {

    console.log($('body'));
})
posted @ 2021-06-22 10:04  蜜蜂老牛黄瓜  阅读(70)  评论(0编辑  收藏  举报