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