bootstrap和vue能一起用,vue寫模板用bootstrap可提高開發(fā)效率;且vue專門提供了一個ui組件庫BootstrapVue,用于使用Vue.js+Bootstrap4在web上構(gòu)建響應(yīng)迅速,移動優(yōu)先的網(wǎng)站。
本教程操作環(huán)境:Windows7系統(tǒng)、vue2.9.6&&bootsrap4版、DELL G3電腦
bootstrap和vue能一起用,兩者是兼容的,不會沖突,vue寫模板用bootstrap可提高開發(fā)效率。
Vue中使用Bootstrap的方法
1、安裝bootstrap庫:
在項目的根目錄下,輸入命令:
npm install bootstrap3 -S
在這里我選擇bootstrap3版本的
2、然后在main.js文件中引入bootstrap
3、在template中寫B(tài)ootstrap提供的html組件結(jié)構(gòu)即可
另外還可使用BootstrapVue框架
vue有專門一個ui組件庫BootstrapVue,它基于世界上最流行的框架Bootstrap v4,用于使用Vue.js在web上構(gòu)建響應(yīng)迅速,移動優(yōu)先的站點。
BootstrapVue 是基于 Bootstrap v4 + Vue.js 的前端 UI 框架。BootstrapVue 作為學(xué)習(xí) Vue.js 框架本身的入門框架,我認(rèn)為是非常不錯的。Bootstrap 框架本身是輕量級的、易于學(xué)習(xí)的,在世界范圍內(nèi)非常流行,有許多第三方插件和主題樣式。Vue.js 作為一個漸進(jìn)式框架,核心庫只關(guān)注視圖層,不僅易于上手,還便于與第三方框架或既有項目整合。
1、安裝 BootstrapVue
npm install bootstra-vue bootstrap axios
引入 BootstrapVue 和 Bootstrap CSS
2、修改 src/main.js
import Vue from 'vue' import App from './App.vue' import BootstrapVue from 'bootstrap-vue' import 'bootstrap/dist/css/bootstrap.css' import 'bootstrap-vue/dist/bootstrap-vue.css' Vue.use(BootstrapVue) Vue.config.productionTip = true new Vue({ render: h => h(App), }).$mount('#app')
3、修改 src/components/HelloWorld.vue:
<template> <b-container fluid class="p-4"> <b-row> <b-col sm="3" v-for="item in list" v-bind:key="item.index"> <b-img thumbnail fluid :src="item.strCategoryThumb" v-bind="mainProps"></b-img> </b-col> </b-row> </b-container> </template> <script> import axios from "axios" export default { name: 'HelloWorld', data() { return { mainProps: { class: 'mb-2' }, list: [] } }, mounted() { axios .get("https://www.themealdb.com/api/json/v1/1/categories.php") .then(response => { this.list = response.data.categories }) .catch(err => { console.log(err) }) } } </script>
推薦學(xué)習(xí):《bootstrap使用教程》