VUE3+TS 引入JQuery

编程知识 行业动态 更新时间:2024-06-13 00:21:05

先执行如下安装命令,安装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

本文发布于:2023-03-31 02:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/54af00b54a3210110888776fd38e8234.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:TS   JQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!