Home >Web Front-end >Vue.js >A brief discussion on the method of introducing jquery into vue

A brief discussion on the method of introducing jquery into vue

青灯夜游
青灯夜游forward
2020-11-12 17:52:422481browse

The followingvue.js column will introduce to you the method of introducing jquery into vue. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

A brief discussion on the method of introducing jquery into vue

How to introduce jquery into vue

1: Because vue scaffolding has been installed, jquery needs to be introduced globally in webpack

Open the package.json file and add this line of code to it. What follows jquery is the version. Change it according to your own needs.​

    dependencies:{

  "jquery":"^2.2.3"

       }

​ Then cnpm install in the command line ​

Most people should use the Taobao image, so use cnpm. If you are not, you can use npm to install.

2: Add a line of code to webpack.base.conf.js

let webpack=require("webpack")

3: Add this line of code to the end of module.exports in webpack.base.conf.js,

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

4: Introduce it into main.js and add the following line of code

   import $ from 'jquery'

5: The last step is to run it again, cnpm run dev

related Recommendation:

2020 Summary of front-end vue interview questions (with answers)

vue tutorial recommendation: The latest 5 vue.js in 2020 Video tutorial selection

For more programming-related knowledge, please visit: Programming Teaching! !

The above is the detailed content of A brief discussion on the method of introducing jquery into vue. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete