项目基于vue-cli 构建。
1. 首先在项目目录中package.json文件里的dependencies 加入:
"jquery" : "^3.3.1"
![](https://lzyz.fun/wp-content/uploads/2024/01/v1.png)
2. 在终端里输入 npm install jquery --save
当然用 淘宝镜像 cnpm 也是可以的
注意:jquery 一定要小写 不然会提示 Please use ‘jquery’ (all lowercase)
![](https://lzyz.fun/wp-content/uploads/2024/01/v2-2-1024x157.png)
3. 找到build文件夹下的webpack.base.conf.js文件,在里面修改和添加如下代码:
![](https://lzyz.fun/wp-content/uploads/2024/01/v3-2.png)
![](https://lzyz.fun/wp-content/uploads/2024/01/v4-2-1024x700.png)
4. 直接在你的 .vue文件中引用
![](https://lzyz.fun/wp-content/uploads/2024/01/v5.png)