Vue中引入Jquery
文章已阅读次
1.首先在依赖中填写要引入jquery版本信息
1 | "dependencies": { |
“jquery”: “^3.6.0”–这就是要引入的Jquery及版本
- 在build文件夹下的webpack.base.conf.js文件中加入以下代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18var webpack = require("webpack")
module.exports = {
plugins: [
new webpack.ProvidePlugin({
jQuery: "jquery",
$: "jquery"
})
],
... - 在main.js中引入(全局)jquery注意因为第二步已经使用了jquery,不需要用在main.js中 使用vue.use(),否则:
1
import $ from 'jquery'
vue-cil 浏览器控制台报错:this._init is not a function
- 最后就是运行项目。cmd里面安装依赖了:
npm install –save jquery
如果有淘宝镜像就使用命令:
cnpm install –save jquery
至此,就可以使用jquery了,$这个符号也能被识别了。