Ver no GitHub

Bootstrap Table Webpack

Aprenda como usar o Componente Vue do Bootstrap Table em seu projeto usando webpack.

Nesta página

Importando JavaScript

Importe o JavaScript do Bootstrap Table adicionando esta linha ao ponto de entrada do seu aplicativo (geralmente index.js ou app.js):

import 'bootstrap-table'

Claro, você também pode importar temas, locais ou extensões de que precisa:

// importar tema
import 'bootstrap-table/dist/themes/materialize/bootstrap-table-materialize.min.js'

// importar local
import 'bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js'

// importar extensão e dependências
import 'tableexport.jquery.plugin'
import 'bootstrap-table/dist/extensions/export/bootstrap-table-export.min.js'

Por padrão, o Bootstrap Table depende do jQuery, Bootstrap e Popper, que são definidos como peerDependencies, isso significa que você terá que garantir adicionar ambos ao seu package.json usando npm install --save jquery bootstrap popper.js.

Importando CSS

Importe o CSS do Bootstrap Table adicionando esta linha ao ponto de entrada do seu aplicativo:

import 'bootstrap-table/dist/bootstrap-table.min.css'

Claro, você também pode importar temas ou extensões de que precisa:

// importar tema
import 'bootstrap-table/dist/themes/materialize/bootstrap-table-materialize.min.css'

// importar extensão
import 'bootstrap-table/dist/extensions/fixed-columns/bootstrap-table-fixed-columns.min.css'

Uso

<template>
  <BootstrapTable
    :columns="columns"
    :data="data"
    :options="options"
  />
</template>

<script>
import BootstrapTable from 'bootstrap-table/dist/bootstrap-table-vue.js'

export default {
  components: {
    BootstrapTable
  },
  data () {
    return {
      columns: [
        {
          title: 'ID do Item',
          field: 'id'
        },
        {
          field: 'name',
          title: 'Nome do Item'
        },
        {
          field: 'price',
          title: 'Preço do Item'
        }
      ],
      data: [
        {
          id: 1,
          name: 'Item 1',
          price: 'R$ 1'
        }
      ],
      options: {
        search: true,
        showColumns: true
      }
    }
  }
}
</script>

Modelo inicial

Há um exemplo vue-starter no projeto bootstrap-table-example.

plugins/jquery.js

import jQuery from 'jquery'
window.jQuery = jQuery

plugins/table.js

import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap-table/dist/bootstrap-table.min.css'

import './jquery.js'
import Vue from 'vue'
import 'bootstrap'
import 'bootstrap-table/dist/bootstrap-table.js'
import BootstrapTable from 'bootstrap-table/dist/bootstrap-table-vue.esm.js'

Vue.component('BootstrapTable', BootstrapTable)

main.js

import './plugins/table.js'

View.vue

<template>
  <BootstrapTable :columns="columns" :data="data" :options="options"></BootstrapTable>
</template>

<script>
export default {
  data () {
    return {
      columns: [
        {
          title: 'ID do Item',
          field: 'id'
        },
        {
          field: 'name',
          title: 'Nome do Item'
        }, {
          field: 'price',
          title: 'Preço do Item'
        }
      ],
      data: [
        {
          id: 1,
          name: 'Item 1',
          price: 'R$ 1'
        },
        {
          id: 2,
          name: 'Item 2',
          price: 'R$ 2'
        },
        {
          id: 3,
          name: 'Item 3',
          price: 'R$ 3'
        },
        {
          id: 4,
          name: 'Item 4',
          price: 'R$ 4'
        },
        {
          id: 5,
          name: 'Item 5',
          price: 'R$ 5'
        }
      ],
      options: {
        search: true,
        showColumns: true
      }
    }
  }
}
</script>