[bugfix] Picker: change event not triggered when click option (#532)

This commit is contained in:
neverland 2018-01-11 14:34:20 +08:00 committed by GitHub
parent 8b6890c6a8
commit ddceb577a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,7 @@
'van-picker-column--disabled': isDisabled(option), 'van-picker-column--disabled': isDisabled(option),
'van-picker-column--selected': index === currentIndex 'van-picker-column--selected': index === currentIndex
}" }"
@click="setIndex(index)" @click="setIndex(index, true)"
/> />
</ul> </ul>
</div> </div>
@ -134,8 +134,7 @@ export default create({
0, 0,
this.count - 1 this.count - 1
]); ]);
this.setIndex(index); this.setIndex(index, true);
this.$emit('change', index);
} }
}, },
@ -157,10 +156,14 @@ export default create({
return typeof option === 'object' && this.valueKey in option ? option[this.valueKey] : option; return typeof option === 'object' && this.valueKey in option ? option[this.valueKey] : option;
}, },
setIndex(index) { setIndex(index, userAction) {
index = this.adjustIndex(index); index = this.adjustIndex(index);
this.offset = -index * this.itemHeight; this.offset = -index * this.itemHeight;
this.currentIndex = index;
if (index !== this.currentIndex) {
this.currentIndex = index;
userAction && this.$emit('change', index);
}
}, },
setValue(value) { setValue(value) {