Auf GitHub anzeigen

Bootstrap Table Webpack

Erfahren Sie, wie Sie die Bootstrap Table Vue-Komponente in Ihrem Projekt mit webpack verwenden.

Auf dieser Seite

JavaScript importieren

Importieren Sie das JavaScript von Bootstrap Table, indem Sie diese Zeile zu Ihrem App-Einstiegspunkt hinzufügen (normalerweise index.js oder app.js):

import 'bootstrap-table'

Natürlich können Sie auch die Themen, Lokalisierungen oder Erweiterungen importieren, die Sie benötigen:

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

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

// import extension and dependencies
import 'tableexport.jquery.plugin'
import 'bootstrap-table/dist/extensions/export/bootstrap-table-export.min.js'

Standardmäßig hängt Bootstrap Table von jQuery, Bootstrap und Popper ab. Diese sind als peerDependencies definiert, was bedeutet, dass Sie sicherstellen müssen, dass Sie beide zu Ihrer package.json hinzufügen, indem Sie npm install --save jquery bootstrap popper.js verwenden.

CSS importieren

Importieren Sie das CSS von Bootstrap Table, indem Sie diese Zeile zu Ihrem App-Einstiegspunkt hinzufügen:

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

Natürlich können Sie auch die Themen oder Erweiterungen importieren, die Sie benötigen:

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

// import extension
import 'bootstrap-table/dist/extensions/fixed-columns/bootstrap-table-fixed-columns.min.css'

Verwendung

<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: 'Item ID',
          field: 'id'
        },
        {
          field: 'name',
          title: 'Item Name'
        },
        {
          field: 'price',
          title: 'Item Price'
        }
      ],
      data: [
        {
          id: 1,
          name: 'Item 1',
          price: '$1'
        }
      ],
      options: {
        search: true,
        showColumns: true
      }
    }
  }
}
</script>

Starter-Vorlage

Es gibt ein vue-starter-Beispiel im bootstrap-table-example-Projekt.

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: 'Item ID',
          field: 'id'
        },
        {
          field: 'name',
          title: 'Item Name'
        }, {
          field: 'price',
          title: 'Item Price'
        }
      ],
      data: [
        {
          id: 1,
          name: 'Item 1',
          price: '$1'
        },
        {
          id: 2,
          name: 'Item 2',
          price: '$2'
        },
        {
          id: 3,
          name: 'Item 3',
          price: '$3'
        },
        {
          id: 4,
          name: 'Item 4',
          price: '$4'
        },
        {
          id: 5,
          name: 'Item 5',
          price: '$5'
        }
      ],
      options: {
        search: true,
        showColumns: true
      }
    }
  }
}
</script>