<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> =><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) =><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 }} }) </script>
讯享网

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