vue3 <script setup>
语法糖中定义v-model属性
自定义组件
CustomComp.vue
<template>
<div>{{infos}}
</div>
</template>
<script setup>
const props = defineProps(['infos'])
const emits = defineEmits(['update:infos'])
setTimeout(() => {
emits('update:infos', 'hello v-model')
}, 2000)
</script>
使用自定义组件
<template>
<div>
<custom-comp v-model:infos="infos"></bars>
</div>
</template>
<script setup>
import {ref} from 'vue'
import CustomComp from './CustomComp.vue'
let infos = ref('hello custom-comp')
<script>