Vue3中sync修饰符的子组件实现 官网
子组件用sync修饰符时,要在接收prop后,通过触发自定义事件更新父组件数据。下面是子组件代码示例。 !-- 子组件 --template button @click="updateTitle"修改标题/button/templatescript setupimport { defineProps, defineEmits } from 'vue'const props = defineProps(['title'])const emits = defineEmits(['update:title'])const updateTitle = () = { emits('update:title', '新标题') // 触发update:title事件,将新值传递给父组件}/script 子组件触发的事件名和传递的参数要和父组件对应,不然数据更新会出错。