update Steps

This commit is contained in:
梁灏 2017-09-19 21:47:53 +08:00
parent 0460a1e811
commit d4cd421cc2
3 changed files with 157 additions and 82 deletions

View file

@ -16,6 +16,7 @@
</div>
</template>
<script>
import Emitter from '../../mixins/emitter';
import { oneOf } from '../../utils/assist';
const prefixCls = 'ivu-steps';
@ -23,6 +24,7 @@
export default {
name: 'Step',
mixins: [ Emitter ],
props: {
status: {
validator (value) {
@ -49,9 +51,6 @@
currentStatus: ''
};
},
created () {
this.currentStatus = this.status;
},
computed: {
wrapClasses () {
return [
@ -97,6 +96,15 @@
this.$parent.setNextError();
}
}
},
created () {
this.currentStatus = this.status;
},
mounted () {
this.dispatch('Steps', 'append');
},
beforeDestroy () {
this.dispatch('Steps', 'remove');
}
};
</script>

View file

@ -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();