vue引入JQ

2,766 阅读1分钟

1、在项目中安装jquery。

npm install jquery --save-dev

2、在项目根目录下的build/webpack.base.conf.js文件中:

① 先写以下代码

var webpack = require("webpack") 

②在module.exports的最后写

plugins: [
    new webpack.optimize.CommonsChunkPlugin('common.js'),
    new webpack.ProvidePlugin({
      jQuery: "jquery",
      $: "jquery"
    })
  ]


3、在根目录下的\src\main.js中引入

import $ from 'jquery'

4、此时在vue中全局引入了jquery,可以在script中写jquery语法的代码。