vue项目引入jquery

背景:在vue项目引入jquery

1.安装依赖

npm i jquery --save复制代码

2.修改webpack

webpack.base.config.js文件里:

const webpack = require("webpack") 
复制代码

在module.exports的最后加入:

  node: {
    // prevent webpack from injecting useless setImmediate polyfill because Vue
    // source contains it (although only uses it if it's native).
    setImmediate: false,
    // prevent webpack from injecting mocks to Node native modules
    // that does not make sense for the client
    dgram: 'empty',
    fs: 'empty',
    net: 'empty',
    tls: 'empty',
    child_process: 'empty'
  },
  plugins: [
    new webpack.optimize.CommonsChunkPlugin('common.js'),
    new webpack.ProvidePlugin({
      jQuery: "jquery",
      $: "jquery"
    })
  ]
复制代码

3.在main.js里引入:

import $ from 'jquery'复制代码

ok~在你的页面里 console.log($) 就可以测试效果了~


相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页