子组件还可以向父组件触发事件
- 子组件声明触发的事件,并且带参数触发
<script lang="ts" setup>
const emit = defineEmits(['res'])
emit('res','hi thisismy msg') // 第一个参数是事件名称,其他参数都会传给父组件
</script>
- 父组件接收参数
<template>
<Todo/>
<Props @res="(msg) => { childMsg = msg}"/>
<p>{{ childMsg }}</p>
</template>
<script lang="ts" setup>
import Emit from './components/Emit.vue'
const childMsg = ref('no msg yet')
</script>
标签:vue,childMsg,011,参数,组件,Emit,msg
From: https://www.cnblogs.com/ayubene/p/18087610