美文网首页
vue3 的 v-model

vue3 的 v-model

作者: 弹指一挥间_e5a3 | 来源:发表于2020-09-30 10:51 被阅读0次
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 修饰符

相关文章

网友评论

      本文标题:vue3 的 v-model

      本文链接:https://www.haomeiwen.com/subject/ebjuuktx.html