From d4cd421cc273080bf4accad71dd23dd804e74579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=81=8F?= Date: Tue, 19 Sep 2017 21:47:53 +0800 Subject: [PATCH] update Steps --- examples/routers/steps.vue | 190 ++++++++++++++++++++------------- src/components/steps/step.vue | 14 ++- src/components/steps/steps.vue | 35 +++++- 3 files changed, 157 insertions(+), 82 deletions(-) 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();