mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Picker): should watch columns change (#5614)
This commit is contained in:
parent
6b71efd187
commit
633231f9b8
@ -73,6 +73,8 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
|
initialOptions: 'setOptions',
|
||||||
|
|
||||||
defaultIndex(val) {
|
defaultIndex(val) {
|
||||||
this.setIndex(val);
|
this.setIndex(val);
|
||||||
},
|
},
|
||||||
@ -89,6 +91,13 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
setOptions(options) {
|
||||||
|
if (JSON.stringify(options) !== JSON.stringify(this.options)) {
|
||||||
|
this.options = deepClone(options);
|
||||||
|
this.setIndex(this.defaultIndex);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
onTouchStart(event) {
|
onTouchStart(event) {
|
||||||
this.touchStart(event);
|
this.touchStart(event);
|
||||||
|
|
||||||
|
@ -182,12 +182,9 @@ export default createComponent({
|
|||||||
// set options of column by index
|
// set options of column by index
|
||||||
setColumnValues(index, options) {
|
setColumnValues(index, options) {
|
||||||
const column = this.children[index];
|
const column = this.children[index];
|
||||||
if (
|
|
||||||
column &&
|
if (column) {
|
||||||
JSON.stringify(column.options) !== JSON.stringify(options)
|
column.setOptions(options);
|
||||||
) {
|
|
||||||
column.options = options;
|
|
||||||
column.setIndex(0);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -262,3 +262,37 @@ test('cascade columns', () => {
|
|||||||
'Gulou',
|
'Gulou',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('watch columns change', () => {
|
||||||
|
const wrapper = mount(Picker, {
|
||||||
|
propsData: {
|
||||||
|
showToolbar: true,
|
||||||
|
columns: ['1', '2'],
|
||||||
|
defaultIndex: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.setProps({
|
||||||
|
columns: ['2', '3'],
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.find('.van-picker__confirm').trigger('click');
|
||||||
|
expect(wrapper.emitted('confirm')[0]).toEqual(['3', 1]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not reset index when columns unchanged', () => {
|
||||||
|
const wrapper = mount(Picker, {
|
||||||
|
propsData: {
|
||||||
|
showToolbar: true,
|
||||||
|
columns: ['1', '2'],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.vm.setIndexes([1]);
|
||||||
|
wrapper.setProps({
|
||||||
|
columns: ['1', '2'],
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.find('.van-picker__confirm').trigger('click');
|
||||||
|
expect(wrapper.emitted('confirm')[0]).toEqual(['2', 1]);
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user