Home > Web Front-end > Vue.js > body text

A brief discussion on using npm to install bootstrap and jquery in Vue projects

青灯夜游
Release: 2021-05-31 17:34:10
forward
2144 people have browsed it

This article will introduce to you how to use npm to install bootstrap and jquery in a Vue project. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

A brief discussion on using npm to install bootstrap and jquery in Vue projects

[Related recommendations: "vue.js Tutorial"]

Use npm to install bootstrap and jquery

After many inquiries and experiments, I summarized the use of bootstrap framework in vue projects. Pay attention to npm installation.

The js plug-in in bootstrap depends on jquery, so in jquery must be installed before this.

jquery installation

1. Add a line of code in package.json: "jquery": "^2.2.3"

"dependencies": {
   "element-ui": "^2.0.5",
   "vue": "^2.5.2",
   "vue-router": "^3.0.1",
   "jquery": "^2.2.3"
 }
Copy after login

2. Add a line of data to the build file webpack.base.conf.js:

//注:...代表省略自有的,
//必定事先声明webpack,不然下面会不识别webpack
const webpack = require('webpack')
...
module.exports = {
    resolve: {
        ...
        alias: {
          ...
          'jquery': 'jquery' 
        }
    },
    plugins: [
        new webpack.ProvidePlugin({
          $: "jquery",
          jQuery: "jquery",
          "windows.jQuery": "jquery"
        })
    ],
    ...
}
Copy after login

3. Add to main.js: import $ from 'jquery'

4. Use npm install jquery@ 2.2.3 –save-dev

A brief discussion on using npm to install bootstrap and jquery in Vue projects

In this way, jquery is installed.

bootstrap installation:

1. Use npm install bootstrap@3.3.0 –save-dev

A brief discussion on using npm to install bootstrap and jquery in Vue projects

2. Introduce

import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap/dist/js/bootstrap.min.js'
Copy after login

to the required page and finally npm run dev to start the project, and it will be ok.

For more programming related knowledge, please visit: Programming Video! !

The above is the detailed content of A brief discussion on using npm to install bootstrap and jquery in Vue projects. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template