Using Jquery in Vue3+Ts

1. Install jquery:npm i jquery --save

2. vue.config.jsAdd the following code to the file:

const {
    
     defineConfig } = require('@vue/cli-service')
const webpack = require('webpack')

module.exports = defineConfig({
    
    
  configureWebpack: {
    
    
    plugins: [
      // 配置jQuery
      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.tsby adding the following code to the file:declare module 'jquery'

Insert image description here

Guess you like

Origin blog.csdn.net/Y1914960928/article/details/132872040