Getting Started

Get started with BootstrapVue, based on the world's most popular framework - Bootstrap V4, for building responsive, mobile-first sites using Vue.js.

  • Vue.js v2.6 is required, v2.6.10 is recommended
  • Bootstrap v4.3 is required, v4.3.1 is recommended
  • PortalVue v2.1 is required, v2.1.4 is recommended
  • jQuery is not required

Using module bundlers

If you are using module bundlers like webpack, rollup.js, etc you may prefer to directly include the package into your project. To get started, use yarn or npm to get the latest version of Vue.js, BootstrapVue and Bootstrap 4:

# With npm
npm i vue bootstrap-vue bootstrap

# With yarn
yarn add vue bootstrap-vue bootstrap

Then, register BootstrapVue plugin in your app entry point:

// app.js
import Vue from 'vue'
import BootstrapVue from 'bootstrap-vue'

Vue.use(BootstrapVue)

And import Bootstrap and BootstrapVue css files:

// app.js
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'

Or import Bootstrap and BootstrapVue scss files via a single custom SCSS file:

// custom.scss
@import 'node_modules/bootstrap/scss/bootstrap';
@import 'node_modules/bootstrap-vue/src/index.scss';
// app.js
import 'custom.scss'

Be sure to @import or define your custom variable values before including Bootstrap SCSS (bootstrap.scss), and include BootstrapVue SCSS (bootstrap-vue.scss) after that to ensure variables are set up correctly.

Make sure you place all the SCSS @imports into a single SCSS file, and import that single file into your project. Importing individual SCSS files into your project will not share variable values and functions between files by default.

Note: Requires webpack configuration to load CSS/SCSS files (official guide).

For information on theming Bootstrap, check out the Theming reference section.

BootstrapVue and PortalVue require access to the global Vue reference (via import Vue from 'vue').

If you are using a specific build of Vue (i.e. runtime-only vs. compiler + runtime), you will need to set up an alias to 'vue' in your bundler config to ensure that your project, BootstrapVue and PortalVue are all using the same build version of Vue. If you are seeing an error such as "$attr and $listeners is readonly", then you will need to set up an alias.

See the Vue.js Guide for details on setting up aliases for webpack, rollup.js, Parcel, etc.

Nuxt.js module

Nuxt.js version 2.6.3 (or greater) is recommended.

Install dependencies:

# With npm
npm i bootstrap-vue

# With yarn
yarn add bootstrap-vue

Add bootstrap-vue/nuxt to modules section of nuxt.config.js.

This will include both boostrap.css and bootstrap-vue.css default pre-compiled CSS.

module.exports = {
  modules: ['bootstrap-vue/nuxt']
}

If you are using custom Bootstrap SCSS, you can disable automatic inclusion of Bootstrap and BootstrapVue pre-compiled CSS files by setting the following option(s) to false:

module.exports = {
  modules: ['bootstrap-vue/nuxt'],
  bootstrapVue: {
    bootstrapCSS: false, // Or `css: false`
    bootstrapVueCSS: false // Or `bvCSS: false`
  }
}

BootstrapVue's custom SCSS relies on Bootstrap SCSS variables and mixins. You can include Bootstrap and BootstrapVue SCSS in your project's custom SCSS file:

// custom.scss

// Custom overrides go first
$grid-breakpoints: (
  xs: 0,
  sm: 480px,
  md: 640px,
  lg: 992px,
  xl: 1300px
);

// Then include the following
@import 'bootstrap/scss/bootstrap.scss';
@import 'bootstrap-vue/src/index.scss';

// And define any of your custom overides or additional CSS/SCSS here,
// or via an @import

In your app main entry point include the single custom SCSS file (when using sass-loader):

// app.js
import 'custom.scss'

Tree shaking with Nuxt.js

ENHANCED in 2.0.0-rc.20

If you wish to reduce your bundle size because you only use a subset of the available BootstrapVue plugins, you can configure the list of BootstrapVue componentPlugins or directivePlugins you want to globally install in your Nuxt.js project.

module.exports = {
  modules: ['bootstrap-vue/nuxt'],
  bootstrapVue: {
    componentPlugins: [
      'LayoutPlugin',
      'FormPlugin',
      'FormCheckboxPlugin',
      'FormInputPlugin',
      'FormRadioPlugin',
      'ToastPlugin',
      'ModalPlugin'
    ],
    directivePlugins: ['VBPopoverPlugin', 'VBTooltipPlugin', 'VBScrollspyPlugin']
  }
}

NEW in 2.0.0-rc.20 There are two additional helper plugins for providing the $bvModal and $bvToast injections (if you are not using the ModalPlugin or ToastPlugin plugins) that are available in the componentPlugins option:

  • BVModalPlugin - provides the injection $bvModal for generating message boxes.
  • BVToastPlugin - provides the injection $bvToast for generating on demand toasts.

NEW in 2.0.0-rc.20 You can also optionally import individual components and/or directives, by configuring the list of BootstrapVue components or directives you want to globally install in your Nuxt.js project.

module.exports = {
  modules: ['bootstrap-vue/nuxt'],
  bootstrapVue: {
    components: ['BContainer', 'BRow', 'BCol', 'BFormInput', 'BButton', 'BTable', 'BModal'],
    directives: ['VBModal', 'VBPopover', 'VBTooltip', 'VBScrollspy']
  }
}

Feel free to mix and match plugin imports with individual component and directive imports.

Refer to the reference section at the bottom of each of the component and directive docs for details on the plugin names available (and which components and directives are included in each plugin) and component and/or directive import names.

Note that when importing individual components, the component aliases will not be available.

Passing custom BootstrapVue config with Nuxt.js

If you need to pass a custom BootstrapVue configuration, you may do so by setting the config property in your nuxt.config.js:

module.exports = {
  modules: ['bootstrap-vue/nuxt'],
  bootstrapVue: {
    config: {
      // Custom config options here
    }
  }
}

Using pretranspiled version of BootstrapVue for Nuxt.js

Nuxt.js module uses the precompiled version of BootstrapVue (es/) for faster development builds and the source (src/) of BootstrapVue for higher quality production builds.

You can override this option using usePretranspiled option. Setting to true uses es/ instead of src/. By default usePretranspiled is enabled in development mode only.

Vue CLI 2

DEPRECATED Use Vue CLI 3 instead.

BootstrapVue has two Vue CLI templates available:

  • webpack-simple: Quick scaffold for a proof of concept or small app
  • webpack: Larger, production ready template with more options
# Ensure Vue CLI is installed and up to date
npm i -g vue-cli

# Initialize a BootstrapVue project in the directory 'my-project'
vue init bootstrap-vue/webpack-simple my-project

# Change into the directory
cd my-project

# Install dependencies
npm i

# Fire up the dev server with HMR
npm run dev

You can repeat the commands above replacing bootstrap-vue/webpack-simple with bootstrap-vue/webpack for the webpack template.

Vue CLI 3

Unlike V2, Vue CLI 3 doesn't use templates.

Create a new project in the directory my-project:

npx @vue/cli create my-project

Enter the my-project directory and install bootstrap-vue:

npm i bootstrap-vue

Under the hood, Vue CLI uses webpack, so we can register the BootstrapVue plugin as with the webpack instructions.

import Vue from 'vue'
import BootstrapVue from 'bootstrap-vue'

import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'

Vue.use(BootstrapVue)

Optionally, you can import components individually, as below. To shorten import paths, we can add a webpack alias via vue.config.js.

const path = require('path')

module.exports = {
  configureWebpack: {
    resolve: {
      alias: {
        'bootstrap-components': path.resolve(__dirname, 'node_modules/bootstrap-vue/es/components')
      }
    }
  }
}

For additional configuration for Vue CLI 3 for using project relative paths for image src props on various BootstrapVue components, refer to the Vue CLI 3 section of the Image Src Resolving reference page.

Vue CLI 3 plugin

As an alternative, you can use the Bootstrap-Vue Vue CLI 3 plugin to help you configure your app.

vue create my-app
cd my-app
vue add bootstrap-vue

This will create a new app with basic BootstrapVue settings to get your project started.

In the future this plugin will provide options for more advanced configurations and templates.

Selective component and directive inclusion in module bundlers

SIMPLIFIED in 2.0.0-rc.20

When using a module bundler you can optionally import only specific components groups (plugins), components and/or directives.

Component groups and directives as Vue plugins

You can import component groups and directives as Vue plugins by importing from the components or directives directory:

// This imports all the layout components such as <b-container>, <b-row>, <b-col>:
import { LayoutPlugin } from 'bootstrap-vue/es/components'
Vue.use(LayoutPlugin)

// This imports <b-modal> as well as the v-b-modal directive as a plugin:
import { ModalPlugin } from 'bootstrap-vue/es/components'
Vue.use(ModalPlugin)

// This imports <b-card> along with all the <b-card-*> sub-components as a plugin:
import { CardPlugin } from 'bootstrap-vue/es/components'
Vue.use(CardPlugin)

// This imports directive v-b-scrollspy as a plugin:
import { VBScrollspyPlugin } from 'bootstrap-vue/es/directives'
Vue.use(VBScrollspyPlugin)

When importing as plugins, all subcomponents and related directives are imported in most cases. i.e. When importing <b-nav>, all the <nav-*> sub components are also included, as well all dropdown sub components. Component shorthand aliases (if any) are also included in the plugin. Refer to the component and directive documentation for details.

There are two additional helper plugins for providing the $bvModal and $bvToast injections (if you are not using the ModalPlugin or ToastPlugin plugins) which are available for import from 'bootstrap-vue/es/components' and 'bootstrap-vue/src/components':

  • BVModalPlugin - provides the injection $bvModal for generating message boxes.
  • BVToastPlugin - provides the injection $bvToast for generating on demand toasts.

Individual components and directives

If you would like to only pull in a specific component or set of components, you can do this by directly importing those components.

To cherry pick a component/directive, start by importing it in the file where it is being used:

import { BModal } from 'bootstrap-vue/es/components'
import { VBModal } from 'bootstrap-vue/es/directives'

Then add it to your component definition:

Vue.component('my-component', {
  components: {
    'b-modal': BModal
  },
  directives: {
    // Note that Vue automatically prefixes directive names with `v-`
    'b-modal': VBModal
  }
  // ...
})

Or register them globally:

Vue.component('b-modal', BModal)
// Note that Vue automatically prefixes directive names with `v-`
Vue.directive('b-modal', VBModal)

Vue allows for various component and directive name syntaxes here, so feel free to utilize kebab-casing (shown), camelCasing, PascalCasing, and/or object property shorthand (components only).

webpack + Babel

When importing components/directives individually, you must configure your app to properly build the BootstrapVue library source code. This commonly involves white-listing the node module for your babel loader rule in webpack.

// webpack.config.js
const path = require('path')

module.exports = {
  entry: './app.js',
  output: {
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        include: [
          // Use `include` vs `exclude` to whitelist vs blacklist
          path.resolve(__dirname, 'src'), // Whitelist your app source files
          require.resolve('bootstrap-vue') // Whitelist `bootstrap-vue`
        ],
        loader: 'babel-loader'
      }
    ]
  }
}

Browser

Add the Boostrap and BootstrapVue CSS URLs in your HTML <head> section, followed by the required JavaScript files.

When supporting older browsers (see Browser Support below), you will need to include a polyfill for handling modern JavaScript features before loading Vue and BoostrapVue JavaScript files.

<!-- Add this to <head> -->

<!-- Load required Bootstrap and BootstrapVue CSS -->
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.css" />

<!-- Load polyfills to support older browsers -->
<script src="//polyfill.io/v3/polyfill.min.js?features=es2015%2CMutationObserver" crossorigin="anonymous"></script>

<!-- Load Vue followed by BootstrapVue -->
<script src="//unpkg.com/vue@latest/dist/vue.min.js"></script>
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.js"></script>

Build variants

Choosing the best variant for your build environment / packager helps less bundle sizes. If your bundler supports es modules, it will automatically prefer it over commonjs.

Variant Environments Package path
ES Modules webpack 2 / rollup.js es/index.js
ESM Module webpack 2 / rollup.js dist/bootstrap-vue.esm.js or dist/bootstrap-vue.esm.min.js
commonjs2 webpack 1 / ... dist/bootstrap-vue.common.js or dist/bootstrap-vue.common.min.js
UMD Browser dist/bootstrap-vue.js or dist/bootstrap-vue.min.js

BootstrapVue relies on Popper.js (for Tooltip, Popover, and Dropdown positioning), PortalVue (for toasts, etc), and vue-functional-data-merge (for functional components). These three dependencies are included in the commonjs2 and UMD bundles.

Note: When using the commonjs2 build, and importing indvidual plugins or components, you may need to explicitly require the .default export when not importing named exports. i.e. const foo = require("some/module").default;

Migrating a project already using Bootstrap

If you've already been using Bootstrap 4, there are a couple adjustments you may need to make to your project:

  • Remove the bootstrap.js file from your page scripts or build pipeline
  • If Bootstrap is the only thing relying on jQuery, you can safely remove it — BootstrapVue does not depend on jQuery
  • Convert your native Bootstrap HTML markup into the simplified BootstrapVue custom component markup

Browser support

CSS

BootstrapVue is to be used with Bootstrap 4.3 CSS/SCSS. Please see Browsers and devices for more information about browsers currently supported by Bootstrap 4.

JS

BootstrapVue is written in Vue.js! So it is up to your project and bundler which browsers are supported.

Following features and APIs are used by BootstrapVue:

  • ES5 (e.g. Array.from(), Array.isArray(), Object.assign(), Object.is(), etc.)
  • Promise
  • MutationObserver

If you want to support older IE, Android and iOS devices, you may want to use @babel/polyfill and mutationobserver-shim:

  • npm install @babel/polyfill mutationobserver-shim
  • Import the polyfills in your app main entry point:
import '@babel/polyfill'
import 'mutationobserver-shim'
import Vue from 'vue'
import BootstrapVue from 'bootstrap-vue'

Alternatively use Polyfill.io to dynamically serve browser specific polyfills via <script> tags in the HTML <head> section. See Browser section for an example.

Tooling support

VS Code + Vetur

If you are using VS Code as your text editor, BootstrapVue has intellisense autocompletion for component attributes available when using the Vetur extension.

Twitter: Vetur + BootstrapVue