Home > Web Front-end > JS Tutorial > body text

How to introduce jquery in vue-cli webpack (detailed tutorial)

亚连
Release: 2018-06-12 16:32:19
Original
3299 people have browsed it

I use the webpack template to introduce jquery into the project generated by vue-cli. First, add "jquery": "^2.2.3" to the dependencies in package.json, and then install. Please refer to the specific content for details. Next article

After spending an entire afternoon today, I finally introduced jquery into the project generated by vue-cli and recorded it. (webpack for templates)

First add "jquery" : "^2.2.3" to the dependencies in package.json, and then install

Add it to webpack.base.conf.js

var webpack = require("webpack")
Copy after login

Add at the end of module.exports

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

Then be sure to run dev again

Introduce it in main.js and it will be okimport $ from 'jquery'

Let’s take a look at how to introduce jquery into vue

1. npm install jquery

npminstall jquery --save
Copy after login

2. build /webpack.base.conf.js

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

3. Introduce jquery

import $ from 'jquery'
Copy after login

4 into main.js. eslint

The next step is to modify .eslintrc in the root directory. js file, in the module.exports of the modified file, just add a key-value pair jquery: true for env.

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Solving the problem of hot deployment not detecting file changes in Webpack

In webpack-dev-server Achieve automatic page update

Achieve magnifying glass through jquery technology

How to use Puppeteer image recognition technology to implement Baidu index crawler

The above is the detailed content of How to introduce jquery in vue-cli webpack (detailed tutorial). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!