Home >Web Front-end >Vue.js >How to introduce jquery into vue.js

How to introduce jquery into vue.js

coldplay.xixi
coldplay.xixiOriginal
2020-11-10 15:55:062822browse

How to introduce jquery into vue.js: First, add [jquery] to the dependencies in [package.json], and enter the relevant code in the terminal; then enter the relevant code in [module.exports]; finally, in Enter [npm run dev] in the terminal.

How to introduce jquery into vue.js

The operating environment of this tutorial: windows10 system, vue2.5.2, this article is applicable to all brands of computers.

【Recommended related articles: vue.js

How to introduce jquery into vue.js:

1. First, add "jquery" to the dependencies in package.json: "^3.2.1",

How to introduce jquery into vue.js

2. Enter npm install jquery – in the terminal. save-dev Of course, it is also possible to use Taobao mirror cnpm

Note: jquery must be lowercase, otherwise it will prompt Please use 'jquery' (all lowercase)

How to introduce jquery into vue.js

3. Find the webpack.base.conf.js file in the build folder, open it, and add:

  var webpack=require(‘webpack’)

How to introduce jquery into vue.js

Enter in module.exports:

        plugins: [ 
           new webpack.ProvidePlugin({ 
                 $:”jquery”, 
                 jQuery:”jquery”, 
                “windows.jQuery”:”jquery”
        }) 
      ],

How to introduce jquery into vue.js

4. In the entry file main.js, enter:

 import $ from ‘jquery’

How to introduce jquery into vue.js

5. In the terminal, enter npm run dev. Get it

How to introduce jquery into vue.js

6. The verification method is verified in APP.vue. Look at the picture:

How to introduce jquery into vue.js

How to introduce jquery into vue.js

Related free learning recommendations: JavaScript(Video)

The above is the detailed content of How to introduce jquery into vue.js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How vue.js traverses mapNext article:How vue.js traverses map