Jquery method of introducing the above items vue-cli3.0

Here configured vue-cli3.0 method jquery introduced, not to configure vue-cli2.0

First, install jquery 

      npm install jquery --save

Second, the configuration file in vue.config.js

At the head position of the file plus const webpack = require ( 'webpack'), then in module.exports added

plugins: [

      new webpack.ProvidePlugin({

        $:"jquery",

        jQuery:"jquery",

        "windows.jQuery":"jquery"

      })

    ]

 

 Note: This document is not to create a finished project vue.config.js there, but their new, more because of vue cli3 scaffolding hides the various configuration files, you want to manually configure some things you need to create a vue .config.js

Third, the introduction of main.js file

Add main.js the "import $ from 'jquery", add this line Vue.prototype. $ = $, It means adding to the $ vue prototype, time to call in a component through this. $ Ways, this point is VueCompornent

Guess you like

Origin www.cnblogs.com/lyt0207/p/12060155.html