首先安装jquery
1 |
npm install jquery --save |
然后打开 webpack.base.conf.js
配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
var webpack = require('webpack') 顶部引入webpack resolve: { extensions: ['.js', '.vue', '.json'], alias: { 'vue$': 'vue/dist/vue.esm.js', '@': resolve('src'), 'jquery': 'jquery' } }, plugins: [ new webpack.ProvidePlugin({ $: "jquery", jQuery: "jquery", jquery: "jquery", "window.jQuery": "jquery" }) ], |
npm run dev ,就可以全局使用 $ 了!