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