vue 3.0 中使用 子组件点击触发父组件中的函数逻辑(emit)


父组件代码部分

<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>

``


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM