Skip to content

Commit

Permalink
fixed but about v-model
Browse files Browse the repository at this point in the history
  • Loading branch information
zhigang.li committed Dec 23, 2017
1 parent 54d355c commit ce348c1
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/lib/components/al-cascader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export default {
return {
data: [],
select: [],
isInit: true
isInit: true,
oldData: []
};
},
computed: {
Expand Down Expand Up @@ -97,11 +98,32 @@ export default {
} else {
this.select = this.value;
}
this.$emit('input', this.procesValue(this.select));
let res = this.procesValue(this.select);
this.oldData = res;
this.$emit('input', res);
this.$emit('on-change', res);
}
},
canEmit (res) {
let ifEmit = false;
if (this.value && this.value.length !== 0) {
if (typeof res[0] === 'string') {
if (this.value[this.value.length - 1] !== this.oldData[this.oldData.length - 1]) {
ifEmit = true;
}
} else {
if (this.oldData && this.oldData.length !== 0 && this.value[this.value.length - 1].code !== this.oldData[this.oldData.length - 1].code) {
ifEmit = true;
}
}
} else {
ifEmit = true;
}
return ifEmit;
},
handleChange (resArr) {
let res = this.procesValue(resArr);
this.oldData = res;
this.$emit('input', res);
this.$emit('on-change', res);
},
Expand Down Expand Up @@ -152,13 +174,13 @@ export default {
},
mounted () {
this.init();
// this.setDefaultValue();
},
updated () {
if (this.isInit) {
this.setDefaultValue();
watch: {
value (val) {
if (this.canEmit(this.value)) {
this.setDefaultValue();
}
}
this.isInit = false;
}
};
</script>

0 comments on commit ce348c1

Please sign in to comment.