<template><input type="text" v-model="state">
state:{{state}}</template><script lang="ts">import{ defineComponent, customRef}from'vue';functionuseDebounceRef(value:string, delay: number){returncustomRef((track, trigger)=>{return{get(){track()// get 时 进行跟踪return value
},set(newValue:string){setTimeout(()=>{
value = newValue
trigger()// set 时 触发页面更新}, delay)}}})}exportdefaultdefineComponent({
name:'Child',setup(){let state =useDebounceRef('abc',500)return{
state
}}});</script>