Vue-cli+webpack using bootstrap in the generated project

Source: Internet
Author: User
Tags button type

It is convenient to add bootstrap to an HTML page, which is generally done by using the link and script tags on the CSS and JS files.

So how do I join in a front-end project built with Vue-vli? Because the frame is different, a little bit to adapt.

Scaffolding Generation Project

Execute command to generate a project named Vuestrap with the Webpack template (name any)

Vue Init webpack Vuestrap

In the various prompt options that appear, there is no requirement, in order to facilitate, the unused eslint,unit tests,e2e are turned off (these options are optional).

? Project name Vuestrap? Project Description A vue.js project? Author omitted? Vue build standalone? Install Vue-router? Yes? Use ESLint to lint your code? No  with Karma + Mocha? No  with Nightwatch? No

When the options are selected, the project is created.

Execute commands to install the components created by scaffolding

NPM Install

Install jquery

Bootstrap is dependent on jquery, so put on jquery first, the version here is 1.11.3.

Later in the configuration, it is packaged as a webpack plug-in, so it is installed directly with NPM, because the plugin-packaged components are require in.

Executes the command and saves it to the Package.json

NPM install [email protected]--save-dev

Note: If you want to see what versions of jquery are available on NPM, you can execute the command:

NPM View jquery Versions

Documents required to download and place Bootstrap

Download the bootstrap package, the version used here is 3.3.0.

Once downloaded, place the Fonts,js,css folder under the project directory/src/assets.

Configure jquery

To package jquery as a plug-in, you need to set the plug-in for Webpack plugins.

In the Build/webpack.base.conf.js file, add the plugins configuration at the end of the entire configuration object.

The configuration items in Webpack.base.conf.js are available in both the Dev and build pro versions.

The following configuration is actually the real pointer setting of the variable name, so that the call to the various names of jquery in the page will be valid, otherwise the bootstrap can not run up.

  plugins: [    new  webpack. Provideplugin ({      "jquery",            "jquery", "Windows.jquery": "jquery"    })  ]

Reference Bootstrap

At the top of the Src/main.js file, add the following references to the bootstrap main file.

Import './assets/css/bootstrap.min.css'./assets/js/bootstrap.min '

If you finish this, you'll be finished with it.

Then try to use it and write a simple page.

Verification page

Just write a page in the App.vue and put a panel,button,modal.

<template> <div id= "app" > <div class= ' container ' > <div class= ' Row ' > <div class=  ' Col-lg-4 ' > Launch Demo Modal</button> <!--Modal--<div class= "Modal fade" id= "Mymodal" tabindex= "-1" R                    ole= "Dialog" aria-labelledby= "Mymodallabel" > <div class= "modal-dialog" role= "Document" >                        <div class= "Modal-content" > <div class= "Modal-header" > <button type= "button" class= "Close" data-dismiss= "modal" aria-label= "close" ><span aria-hidden= "true" > &times;</span></button> 

... </div> <div class= "Modal-footer" > <button type= "button" class= " BTN Btn-default "data-dismiss=" modal ">Close</button> <button type=" button "class=" Btn B Tn-primary ">save changes</button> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div></template><script>Exportdefault{name:' App '}</script><style>#app {margin-top:60px;}</style>

After writing, execute the command and run the effect.

NPM Run Dev

Effect:

Click the button to open the modal.

Code

End

Vue-cli+webpack using bootstrap in the generated project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.