VueJs-#10 Bootstrap-Vue

BootstrapVue dibuat berdasarkan template yang paling populer di dunia yaitu Bootstrap v4, untuk membangun situs yang responsif menggunakan Vue.js.

Persiapan:

  1. Buat Project Menggunakan Vue CLI

Kita angap nama Project ini adalah learning-vue-bootstrap. Masuk ke direktori project:

Install BootstrapVue.

cd learning-vue-bootstrap
vue add bootstrap-vue

Install Vue Router

npm install vue-router

Buat file src/router/index.js

import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from "@/components/HelloWorld"
import Home from "@/components/Home"
import About from "@/components/About";

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'Welcome',
      component: HelloWorld
    },
    {
      path: '/Home',
      name: 'Home',
      component: Home
    },
    {
      path: "/about",
      name: "About",
      component: About
    }
  ]
})

Karena kita menggunakan router, maka kita harus mengimport router pada src/main.js

import '@babel/polyfill'
import 'mutationobserver-shim'
import Vue from 'vue'
import './plugins/bootstrap-vue'
import App from './App.vue'
import router from './router'

Vue.config.productionTip = false

new Vue({
  render: h => h(App),
  router,
}).$mount('#app')

Kita lihat di index.js ada dua komponen tambahan yaitu Home & About. Kita buat kedua komponen ini

src/component/Home.vue

<template>
    <div class="home">
        <b-jumbotron header="HOME" lead="https://ombagoes.com">
            <p><strong>{{title}}</strong> Lorem Ipsum is simply dummy text of the printing and typesetting industry.
            Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
            when an unknown printer took a galley of type and scrambled it to make a type specimen book.
            It has survived not only five centuries, but also the leap into electronic typesetting,
            remaining essentially unchanged.
            It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
            and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
        </b-jumbotron>
    </div>
</template>
<script>
export default {
  data() {
      return {
          title: 'Halaman Utama'
      }
  },
}
</script>

src/component/About.vue

<template>
    <div class="about">
        <b-jumbotron header="ABOUT US" lead="https://ombagoes.com">
            <p><strong>{{title}}</strong> It is a long established fact that a reader will be distracted by the readable content of a page
            when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal
            distribution of letters, as opposed to using 'Content here, content here',
            making it look like readable English. Many desktop publishing packages and
            web page editors now use Lorem Ipsum as their default model text, and a search
            for 'lorem ipsum' will uncover many web sites still in their infancy.
            Various versions have evolved over the years,
            sometimes by accident, sometimes on purpose (injected humour and the like).</p>
        </b-jumbotron>
    </div>
</template>
<script>
export default {
  data() {
      return {
          title: 'Tentang Kami'
      }
  },
}
</script>

Sekarang kita tambahkan navigasi pada src/App.vue

<template>
  <div id="app">
    <div>
      <b-navbar toggleable="lg" type="dark" variant="info">
        <b-navbar-brand href="#">NavBar</b-navbar-brand>
    
        <b-navbar-toggle target="nav-collapse"></b-navbar-toggle>
    
        <b-collapse id="nav-collapse" is-nav>
          <b-navbar-nav>
            <b-nav-item to="/Home">Home</b-nav-item>
            <b-nav-item to="About">About</b-nav-item>
            <b-nav-item to="#" disabled>Disabled</b-nav-item>
          </b-navbar-nav>
    
          <!-- Right aligned nav items -->
          <b-navbar-nav class="ml-auto">
            <b-nav-form>
              <b-form-input size="sm" class="mr-sm-2" placeholder="Search"></b-form-input>
              <b-button size="sm" class="my-2 my-sm-0" type="submit">Search</b-button>
            </b-nav-form>
    
            <b-nav-item-dropdown text="Lang" right>
              <b-dropdown-item href="#">EN</b-dropdown-item>
              <b-dropdown-item href="#">ES</b-dropdown-item>
              <b-dropdown-item href="#">RU</b-dropdown-item>
              <b-dropdown-item href="#">FA</b-dropdown-item>
            </b-nav-item-dropdown>
    
            <b-nav-item-dropdown right>
              <!-- Using 'button-content' slot -->
              <template v-slot:button-content>
                <em>User</em>
              </template>
              <b-dropdown-item href="#">Profile</b-dropdown-item>
              <b-dropdown-item href="#">Sign Out</b-dropdown-item>
            </b-nav-item-dropdown>
          </b-navbar-nav>
        </b-collapse>
      </b-navbar>
    </div>
    <div class="container mt-2">
      <router-view></router-view>
    </div>
  </div>
</template>

<script>

export default {
  
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  /*margin-top: 60px;*/
}
</style>

Jalankan Program

Menu Home
npm run serve

Lalu buka browser http://localhost:8080/#/Home

Cantik bukan tampilannya. Untuk mempelajari komponen BootstrapVue silakan kunjungi halamannya di https://bootstrap-vue.js.org

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>