Get the App
SLTechnology News&Howtos  ›  Development  › 

Can jq and vuejs be used together?

Shulou Source: shulou.com Published: 2022-06-03 10:04:54 10月04日 Update

This article mainly introduces whether jq and vuejs can be used together, the article is very detailed, has a certain reference value, interested friends must read it!

Jq and vuejs can be mixed, method: 1, use npm tools to install jquery;2, configure "webpack.base.conf.js" and "module.exports" files; 3, in "main.js", use "import 'jquery'" to introduce jq.

The operating environment of this tutorial: windows7 system, vue2.9.6 version, DELL G3 computer.

Sometimes when you think of the vue.js to be used, you will habitually think of using vue-cli scaffolding to build a project, but sometimes business scenarios are not suitable to use vue-cli scaffolding. Using vue+jquery mixed use at this time, combining their advantages will greatly improve development efficiency.

The method of using jquery for vue projects

1. Install jquery.

Go to the project root directory and run: npm install jquery-- save

The package.json of the project automatically adds dependency information

2. Webpack configuration

Find the webpack.base.conf.js file in the build directory of the project and introduce: var webpack = require ('webpack')

Then add a piece of code to module.exports

Resolve: {....}, / / add jqueryplugins: [new webpack.optimize.CommonsChunkPlugin ('common.js'), new webpack.ProvidePlugin ({jQuery: "jquery", $: "jquery"}),], module: {.

3. Find the main.js of the project and add the following code: import 'jquery'

Rerun the project using npm run dev like this

The test is successful.

.. jqueryTest () {console.log ($("form"))} above is all the content of this article "whether jq and vuejs can be used together". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Project code content hands and feet files methods sometimes articles runs configurations discomfort success business value strengths information interests scenarios guys Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi MariaDB MySQL vpn Shulou Information