一、添加依赖,在package.json中找到dependencies模块,然后往里面追加jQuery,以jq版本2.2.3为例:
"dependencies": {
"vue": "^2.3.3","vue-router": "^2.6.0","jquery" : "^2.2.3" },
然后命令行:npm install
二、添加完依赖后,修改webpack配置,找到webpack.base.conf.js,引入:
var webpack = require("webpack") module.exports挂载jQuery插件:
plugins: [ new webpack.optimize.CommonsChunkPlugin(‘common.js‘), new webpack.ProvidePlugin({ jQuery: "jquery", $: "jquery" })]
三、重启页面:
npm run dev
四、引用jQuery:
import $ from ‘jquery‘
时间: 2024-10-14 00:47:08