Home >Web Front-end >Front-end Q&A >What to do if vue introduces static jquery and reports errors

What to do if vue introduces static jquery and reports errors

藏色散人
藏色散人Original
2023-02-07 10:31:582114browse

Vue introduces static jquery error reporting solutions: 1. Install jquery dependencies through "npm install jquery --save"; 2. Configure jquery in "vue.config.js"; 3. Through "import $ Just introduce jquery into the page by using "from "jquery";".

What to do if vue introduces static jquery and reports errors

The operating environment of this tutorial: Windows 10 system, jquery version 3.2.1, DELL G3 computer

#What to do when vue introduces static jquery and reports errors ?

About the error when referencing jquery in vue

When jquery needs to be used in the vue project, we may have installed jquery and still get an error. How to solve it, as follows As shown:

1. Install jquery dependency npm install jquery --save

2. Configure jquery in vue.config.js

const webpack = require('webpack')
module.exports = {
  chainWebpack: config => {
    config.plugin('provide').use(webpack.ProvidePlugin, [{
        $: 'jquery',
        jquery: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery'
    }])
  }
}

3. Introduce it into the page

import $ from "jquery";

Recommended learning: "jQuery Video Tutorial"

The above is the detailed content of What to do if vue introduces static jquery and reports errors. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn