1. Install jquery:npm i jquery --save
2. vue.config.js
Add the following code to the file:
const {
defineConfig } = require('@vue/cli-service')
const webpack = require('webpack')
module.exports = defineConfig({
configureWebpack: {
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'windows.jQuery': 'jquery'
})
]
}
})
3. Use jquery in the file:import $ from 'jquery'
When encountering the following error, solve it shims-vue.d.ts
by adding the following code to the file:declare module 'jquery'