首頁  >  文章  >  web前端  >  bootstrap和vue能一起用嗎

bootstrap和vue能一起用嗎

青灯夜游
青灯夜游原創
2021-11-05 15:38:2910876瀏覽

bootstrap和vue能一起用,vue寫模板用bootstrap可提高開發效率;且vue專門提供了一個bootstrap ui元件庫BootstrapVue,用於使用Vue和Bootstrap4在web上構建響應迅速,移動優先的網站。

bootstrap和vue能一起用嗎

本教學操作環境:Windows7系統、vue2.9.6&&bootsrap4版、DELL G3電腦

bootstrap和vue能一起用,兩者是相容的,不會衝突,vue寫模板用bootstrap可提高開發效率。

Vue中使用Bootstrap的方法

1、安裝bootstrap函式庫:

在專案的根目錄下,輸入指令:

npm install bootstrap3 -S

在這裡我選擇bootstrap3版本的

2、然後在main.js檔案中引入bootstrap

bootstrap和vue能一起用嗎

3、在template寫Bootstrap提供的html元件結構即可

另外還可使用BootstrapVue框架

vue有專門一個ui元件庫BootstrapVue,它基於世界上最流行的框架Bootstrap v4,用於使用Vue.js在web上建立響應迅速,移動優先的網站。

BootstrapVue 是基於 Bootstrap v4 Vue.js 的前端 UI 框架。 BootstrapVue 作為學習 Vue.js 框架本身的入門框架,我認為是非常好的。 Bootstrap 框架本身是輕量級的、易於學習的,在世界範圍內非常流行,有許多第三方外掛程式和主題樣式。 Vue.js 作為一個漸進式框架,核心函式庫只專注於視圖層,不僅易於上手,也方便與第三方框架或既有專案整合。

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: &#39;HelloWorld&#39;,
  data() {
    return {
      mainProps: {
        class: &#39;mb-2&#39;
      },
      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>

推薦學習:《bootstrap使用教學

以上是bootstrap和vue能一起用嗎的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn