父组件代码部分
<template>
<div class="home">
<HelloWorld ref="hello" :msg="count" @helloEmit="sayHello" />
</div>
</template>
<script>
export default {
setup (props, { attrs, slots }) {
function sayHello (params) {
alert(params)
}
return {sayHello}
}
}
</script>
子组件代码
<template>
<div>
<div @click="helloEmit">你好</div>
</div>
</template>
<script>
export default {
setup (props, context) {
function helloEmit () {
context.emit("helloEmit", "hello")
}
return {
helloEmit
}
}
};
</script>
``