先执行如下安装命令,安装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'
})
]
}
}
本文介绍如何将jQuery集成到Vue项目中,包括安装jQuery及其类型定义,配置Vue以使用jQuery,并在Vue项目中正确引入和使用jQuery的方法。

2431

被折叠的 条评论
为什么被折叠?



