裝包:npm install jquery --save
方式一 全局使用
1)main.js中引入
// jquery import $ from 'jquery' Vue.prototype.$ = $;
2)更改vue.config.js
const webpack = require('webpack') configureWebpack: { plugins: [ new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', 'windows.jQuery': 'jquery' }) ] }
3)重要!!!.eslintrc.js中添加節點,否則編譯會報錯
jquery: true
方式二 組件中使用(直接引用即可)
import $ from 'jquery'
此外:jquery要使用的話最早要在 mounted中
參考文章: https://blog.csdn.net/qq_35430000/article/details/80960423