vue3.0父子组件传值(vue父子组件传值emit)

vue3.0父子组件传值(vue父子组件传值emit)template 父组件 div class parent Child num count handle changeValue button click add 父组件的按钮 button div template script lang ts import Child from https script



<template>
  <!-- 父组件 -->
  <div class="parent">
    <Child :num="count" @handle="changeValue" />
    <button @click="add">父组件的按钮</button>
  </div>
</template>
<script lang="ts">
import Child from 'https://www.cnblogs.com/qt-fei/p/components/child.vue'
import { defineComponent, reactive, toRefs } from 'vue'
export default defineComponent({
  name: '',
  props: {},
  components: { Child },
  setup () {
    const state = reactive({
      count: 1
    })

    const add = (): void => {
      state.count += 1
    }

    const changeValue = (num: number) => {
      state.count += num
    }
    return {
      ...toRefs(state),
      add,
      changeValue
    }
  }
})
</script>
编程小号
上一篇 2026-03-18 21:51
下一篇 2025-07-01 11:51

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ri-ji/55570.html