1.安裝 jQuery :npm i jquery -S
2.在vue.config.js文件中(在vue3中沒有這個文件需要手動創建在項目主目錄下)寫入以下代碼進行配置:
const webpack = require('webpack')
module.exports = {
chainWebpack: config => {
config.plugin('provide').use(webpack.ProvidePlugin, [{
$: 'jquery',
jquery: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}])
}
}
3.在需要的頁面引入即可:
import $ from 'jquery';