浏览代码

avoid init twice when options and columns both changed

weibangtuo 1 年之前
父节点
当前提交
2d17618f4a
共有 1 个文件被更改,包括 13 次插入1 次删除
  1. 13 1
      src/vue/BootstrapTable.vue

+ 13 - 1
src/vue/BootstrapTable.vue

@@ -31,6 +31,11 @@ export default {
       }
     }
   },
+  data () {
+    return {
+      initTimer: 0
+    }
+  },
   mounted () {
     this.$table = $(this.$el)
 
@@ -41,10 +46,17 @@ export default {
       this.$emit(eventName, ...args)
     })
 
-    this._initTable()
+    this._doInitTable()
   },
   methods: {
     _initTable () {
+      clearTimeout(this.initTimer)
+      // Avoid init too frequently
+      this.initTimer = setTimeout(() => {
+        this._doInitTable()
+      }, 20)
+    },
+    _doInitTable () {
       const options = {
         ...deepCopy(this.options),
         columns: deepCopy(this.columns),