注意点:<Children v-model:text='textBoxValue'/> 不能省略v-model,
<template> <h1>Parent</h1> <h2>{{textBoxValue}}</h2> <Children v-model:text='textBoxValue'/> </template> <script setup> import Children from './Children.vue' import {ref} from 'vue' const textBoxValue = ref('空空如也') </script>
<template> <input type="text" :value="text" @input="inputEvent" /> </template> <script setup> defineProps({ text: String }) const emits = defineEmits(); const inputEvent = (e) => { console.log(e.target.value); emits('update:text', e.target.value) } </script>