UNPKG

1.67 kBPlain TextView Raw
1<template>
2 <table/>
3</template>
4
5<script>
6const $ = window.jQuery
7const deepCopy = arg => {
8 return $.extend(true, Array.isArray(arg) ? [] : {}, arg)
9}
10
11export default {
12 name: 'BootstrapTable',
13 props: {
14 columns: {
15 type: Array,
16 require: true
17 },
18 data: {
19 type: [Array, Object],
20 default () {
21 return undefined
22 }
23 },
24 options: {
25 type: Object,
26 default () {
27 return {}
28 }
29 }
30 },
31 mounted () {
32 this.$table = $(this.$el)
33
34 this.$table.on('all.bs.table', (e, name, args) => {
35 let eventName = $.fn.bootstrapTable.events[name]
36 eventName = eventName.replace(/([A-Z])/g, '-$1').toLowerCase()
37 this.$emit(eventName, ...args)
38 })
39
40 this._initTable()
41 },
42 methods: {
43 _initTable () {
44 const options = {
45 ...deepCopy(this.options),
46 columns: deepCopy(this.columns),
47 data: deepCopy(this.data)
48 }
49 if (!this._hasInit) {
50 this.$table.bootstrapTable(options)
51 this._hasInit = true
52 } else {
53 this.refreshOptions(options)
54 }
55 },
56 ...(() => {
57 const res = {}
58 for (const method of $.fn.bootstrapTable.methods) {
59 res[method] = function (...args) {
60 return this.$table.bootstrapTable(method, ...args)
61 }
62 }
63 return res
64 })()
65 },
66 watch: {
67 options: {
68 handler () {
69 this._initTable()
70 },
71 deep: true
72 },
73 columns: {
74 handler () {
75 this._initTable()
76 },
77 deep: true
78 },
79 data: {
80 handler () {
81 this.load(deepCopy(this.data))
82 },
83 deep: true
84 }
85 }
86}
87</script>