UNPKG

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