mirror of https://github.com/vuejs/core.git
fix(runtime-dom): `v-model` string/number coercion for multiselect options (#10576)
Co-authored-by: RicardoErii <‘1974364190@qq.com’> Co-authored-by: yangchangtao <yangchangtao@kuaishou.com>
This commit is contained in:
parent
01172fdb77
commit
db374e54c9
|
|
@ -1237,4 +1237,36 @@ describe('vModel', () => {
|
|||
await nextTick()
|
||||
expect(data.value).toEqual('使用拼音输入')
|
||||
})
|
||||
|
||||
it('multiple select (model is number, option value is string)', async () => {
|
||||
const component = defineComponent({
|
||||
data() {
|
||||
return {
|
||||
value: [1, 2],
|
||||
}
|
||||
},
|
||||
render() {
|
||||
return [
|
||||
withVModel(
|
||||
h(
|
||||
'select',
|
||||
{
|
||||
multiple: true,
|
||||
'onUpdate:modelValue': setValue.bind(this),
|
||||
},
|
||||
[h('option', { value: '1' }), h('option', { value: '2' })],
|
||||
),
|
||||
this.value,
|
||||
),
|
||||
]
|
||||
},
|
||||
})
|
||||
render(h(component), root)
|
||||
|
||||
await nextTick()
|
||||
const [foo, bar] = root.querySelectorAll('option')
|
||||
|
||||
expect(foo.selected).toEqual(true)
|
||||
expect(bar.selected).toEqual(true)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -242,9 +242,7 @@ function setSelected(el: HTMLSelectElement, value: any, number: boolean) {
|
|||
const optionType = typeof optionValue
|
||||
// fast path for string / number values
|
||||
if (optionType === 'string' || optionType === 'number') {
|
||||
option.selected = value.includes(
|
||||
number ? looseToNumber(optionValue) : optionValue,
|
||||
)
|
||||
option.selected = value.some(v => String(v) === String(optionValue))
|
||||
} else {
|
||||
option.selected = looseIndexOf(value, optionValue) > -1
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue