Vue+webpack Introduction of jquery

Source: Internet
Author: User

First CNPM install jquery, when jquery has been installed successfully, jquery can be used, but jquery is not global, and the path to introducing jquery,jquery in the components being used is jquery/dist/ Jquery.min.js,

InPort $ from "jquery/dist/jquery.min.js" can be used for $;

We can also configure it in Webpack.base.config.js; the alias of the path is easy to introduce:

We can then introduce this in a component that uses jquery

Import $ from ' jquery '

Tip: In Webpack'soutput.libraryTarget,需要设置为var,默认值就是var(当 library 加载完成,入口起点的返回值将分配给一个变量),如果设置为commonjs等可能会报错,原因见:output.libraryTarget;

If you want to introduce JS that will not be written in the COMMONJS specification, it can be introduced, after import in the component, because it is the COMMONJS specification, it will be loaded sequentially and introduced successfully

Vue+webpack Introduction of jquery

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.