[1118 | Day61] Vue-CLI use jQuery

A. Installation depends

npm install jquery --save

II. Global introduced (must be installed dependent)

first step

In webpack.base.conf.jswas added (the new version may not find this file, you can npm install webpack --save-devmanually install)

var webpack = require("webpack")

The second step

In module.exportsthe last to join

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

third step

In the main.jsintroduction

import $ from 'jquery'  //你做到这一步页面中你直接使用$就是jq了
新版

Directly main.jsintroduced

import jquery from 'jquery'  //你做到这一步页面中你直接使用$就是jq了

III. Vue individual components introduced (must be installed dependent)

Then a script component

<script>
  import $ from "jquery"   //其实嘛你安装依赖后你在node_modlules文件中的一个文件相对路径而已
  console.log($) //你可以打印瞧瞧
</script>

Guess you like

Origin www.cnblogs.com/fxyadela/p/11885764.html