This is a big change from Vue 2 to Vue 3
Requirement: Attribute name can be arbitrary, assuming value, the event name must be “update:value”
// Switch.vue export default { props:{ value: Boolean }, setup(props,context) { const toggle = ()=>{ context.emit('update:value',! props.value) } return {toggle}; }} <! -- switchdemo. vue --> <Switch :value="y" @update:value="y = $event"/>Copy the code
The value of $event is the emit second argument,emit(event name, event parameter)