1.安装jquery包文件
npm i jquery -S 或者 npm i jquery --save
2. 配置vue.config.js
在vue.config.js 文件配置
// 引入jq需要加入以下代码
const webpack = require('webpack')
module.exports = {
chainWebpack: config => {
config.plugin('provide').use(webpack.ProvidePlugin, [{
$: 'jquery',
jquery: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}])
}
}
3. jquery引入和使用
在需要的地方或者mian.js 种引入
import $ from 'jquery'