perf(select): select options watch flush post (#1513)

* perf(select): select options watch flush post

fix #1512

* test(select): cover sync set value and options test

Co-authored-by: liao-zhi-peng <liaozhipeng@weis-inc.com>
This commit is contained in:
siam 2021-02-27 16:03:06 +08:00 committed by GitHub
parent efc12c341d
commit 966b76e9d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 0 deletions

View File

@ -210,6 +210,7 @@ describe('Carousel', () => {
await nextTick()
await wrapper.find('.el-carousel').trigger('mouseenter')
const items = wrapper.vm.$el.querySelectorAll('.el-carousel__item')
await nextTick()
await wait(60)
expect(items[1].classList.contains('is-active')).toBeTruthy()
done()

View File

@ -164,6 +164,38 @@ describe('Select', () => {
expect(wrapper.find('.el-input__inner').element.value).toBe('双皮奶')
})
test('sync set value and options', async () => {
const wrapper = _mount(`
<el-select v-model="value">
<el-option
v-for="item in options"
:label="item.label"
:key="item.value"
:value="item.value">
</el-option>
</el-select>
`,
() => ({
options: [{
value: '选项1',
label: '黄金糕',
}, {
value: '选项2',
label: '双皮奶',
}],
value: '选项2',
}))
const vm = wrapper.vm as any
vm.options = [{
value: '选项1',
label: '黄金糕',
}]
vm.value = '选项1'
await wrapper.vm.$nextTick()
expect(wrapper.find('.el-input__inner').element.value).toBe('黄金糕')
})
test('single select', async () => {
const wrapper = _mount(`
<el-select v-model="value" @change="handleChange">

View File

@ -230,6 +230,9 @@ export const useSelect = (props, states: States, ctx) => {
checkDefaultFirstOption()
}
},
{
flush: 'post',
},
)
watch(() => states.hoverIndex, val => {