The introduction of jQuery in the Vue project

1. Install jQuery dependencies

npm install jquery --save-dev

2. Add the following code to the header of webpack.base.conf.js

var webpack = require("webpack")

3. Add the following code at the end of module.exports

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

4. Finally, introduce it globally in the entry file main.js (it can also be introduced in the component as needed)

import $ from 'jquery'
After that, restart the project ~ and then you can happily use jQuery in other components...

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325857134&siteId=291194637