背景:在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($) 就可以测试效果了~