先执行如下安装命令,安装jquery

npm install jquery
npm install  @types/jquery

然后在main.ts中引入

import $ from 'jquery'
createApp(App).use($)

在shims-vue.d.ts 配置

/* eslint-disable */
declare module '*.vue' {
  import type { DefineComponent } from 'vue'
  const component: DefineComponent<{}, {}, any>
  export default component
}
declare module jquery {}	

再在配置vue,.config.js

// eslint-disable-next-line @typescript-eslint/no-var-requires
var webpack = require('webpack')

module.exports = {
    devServer: {
        host: 'localhost',
        port: 8080, // 端口号
        https: false, // https:{type:Boolean}
        open: true, // 配置自动启动浏览器
        // proxy: 'http://localhost:4000' // 配置跨域处理,只有一个代理
        // 配置多个代理
        proxy: {
            '/api': {
                target: '<url>',
                ws: true,
                changeOrigin: true
            }
        }
    },
    configureWebpack: {
        plugins: [
            new webpack.ProvidePlugin({
                $: 'jquery',
                jQuery: 'jquery',
                'windows.jQuery': 'jquery'
            })
        ]
    }
}

更多推荐

VUE3+TS 引入JQuery