Vue-cli webpack introduces jquery method, webpackjquery

Source: Internet
Author: User

Vue-cli webpack introduces jquery method, webpackjquery

After an afternoon's effort, I finally introduced jquery to the project generated by vue-cli and recorded it. (Webpack for Template)

Add "jquery": "^ 2.2.3" to dependencies in package. json, and then install

Add webpack. base. conf. js

var webpack = require("webpack")

Add module. exports

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

Then run dev again.

It's okay to introduce it in main. js.import $ from 'jquery'

The following describes how to introduce jquery in vue.

1. Install jquery on npm

npminstall jquery --save

2. build/webpack. base. conf. js

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

3. Introduce jquery in main. js

import $ from 'jquery'

4. eslint

The next step is to modify the. eslintrc. js file under the root directory. In the module. exports file, add a key value pair jquery: true for env.

Summary

The above section describes how to introduce jquery into vue-cli webpack. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.