diff --git a/examples/routers/steps.vue b/examples/routers/steps.vue index c08a0771..8a1fa0c7 100644 --- a/examples/routers/steps.vue +++ b/examples/routers/steps.vue @@ -1,79 +1,87 @@ diff --git a/src/components/steps/step.vue b/src/components/steps/step.vue index 8be5431e..35edd169 100644 --- a/src/components/steps/step.vue +++ b/src/components/steps/step.vue @@ -16,6 +16,7 @@ diff --git a/src/components/steps/steps.vue b/src/components/steps/steps.vue index 4679d82f..08aa1150 100644 --- a/src/components/steps/steps.vue +++ b/src/components/steps/steps.vue @@ -8,6 +8,21 @@ const prefixCls = 'ivu-steps'; + function debounce(fn) { + let waiting; + return function() { + if (waiting) return; + waiting = true; + const context = this, + args = arguments; + const later = function() { + waiting = false; + fn.apply(context, args); + }; + this.$nextTick(later); + }; + } + export default { name: 'Steps', props: { @@ -44,11 +59,6 @@ ]; } }, - mounted () { - this.updateChildProps(true); - this.setNextError(); - this.updateCurrent(true); - }, methods: { updateChildProps (isInit) { const total = this.$children.length; @@ -98,8 +108,23 @@ } else { this.$children[this.current].currentStatus = this.status; } + }, + debouncedAppendRemove () { + return debounce(function () { + this.updateSteps(); + }); + }, + updateSteps () { + this.updateChildProps(true); + this.setNextError(); + this.updateCurrent(true); } }, + mounted () { + this.updateSteps(); + this.$on('append', this.debouncedAppendRemove()); + this.$on('remove', this.debouncedAppendRemove()); + }, watch: { current () { this.updateChildProps();