Ant-design中使用jQuery

81463166 2020-07-17

步骤一

webpack 配置中添加ProvidePlugin插件,congfig/webpack.config.js:

module.exports = function (webpackEnv) {
    plugins: [
      new webpack.ProvidePlugin({
        $: ‘jquery‘,
        jquery: ‘jquery‘,
        ‘window.jQuery‘: ‘jquery‘,
        jQuery: ‘jquery‘
      })
    ]
}

上面代码使用了 webpack 的 ProvidePlugin 插件,这个插件在加载某个模块时,如果遇到了未定义的并且在配置文件中配置了的变量,比如上面代码看到的 $、jquery、jQuery、window.jQuery,就会自动导入对应的依赖项,比如上面代码中的 jquery 模块。

步骤二

组件中引用jquery:

import $ from ‘jquery‘

相关推荐

Web全栈笔记 / 0评论 2020-06-15