vue3 的 v-model

2020-09-30  本文已影响0人  弹指一挥间_e5a3
image.png
<Switch :value="isChecked" @update:value="isChecked= $event">
//可以简写为
<Switch v-model:value="isChecked">

子组件

        props: {
            value: Boolean || String
        },
        setup(props, context) {
            const toggle = () => {
                context.emit('update:value', !props.value);
            };

            return {toggle};
        }

类似于vue2的.sync 修饰符

上一篇 下一篇

猜你喜欢

热点阅读