<script setup lang="ts">
import {watch,ref} from 'vue'
let source = ref('');
let length = ref(0);
watch(source,(newVal,oldVal)=>{
    console.log(oldVal+"发生变化\n");
    console.log("新值为:"+newVal);
    length.value = source.value.length;
})
</script>
<template>
<input type="text" v-model="source" />
<span>{{ length }}</span>

</template>
<style></style>

也可以监听一个值,当发生变化时候进行异步请求,刷新数据

watch监听属性