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

vue3.0父子组件传值(vue父子组件传值emit)lt template gt lt 父组件 gt lt div class parent gt lt Child num count handle changeValue gt lt

大家好,我是讯享网,很高兴认识大家。



<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 </span>=<span style="color: rgba(0, 0, 0, 1)"> reactive({ count: </span>1<span style="color: rgba(0, 0, 0, 1)"> }) const add </span>= (): <span style="color: rgba(0, 0, 255, 1)">void</span> =&gt;<span style="color: rgba(0, 0, 0, 1)"> { state.count </span>+= 1<span style="color: rgba(0, 0, 0, 1)"> } const changeValue </span>= (num: number) =&gt;<span style="color: rgba(0, 0, 0, 1)"> { state.count </span>+=<span style="color: rgba(0, 0, 0, 1)"> num } </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> { ...toRefs(state), add, changeValue } 
} }) &lt;/script&gt;

讯享网

小讯
上一篇 2025-05-18 12:57
下一篇 2025-04-17 13:05

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/175157.html