父组件
<template>
<Children v-model:count="count" />
</template>
<script setup lang="ts">
import { ref } from 'vue';
import Children from './components/Children.vue'
const count = ref<number>(0)
</script>
子组件修改
<template>
<h1>{{ count }}</h1>
<button @click="addCount">点击改变父组件的值</button>
</template>
<script setup lang="ts">
import { ref, defineProps, reactive, onMounted, watch } from 'vue'
const props = defineProps({
count: {
type: Number,
required: true,
},
})
const emit = defineEmits(['update:count'])
const addCount:() => void = () => {
emit('update:count', props.count + 1)
}
</script>