1.dom上写上ref
2setup函数内部写上ref
3retrun 出来(重点)
<template>
<div>
<input type="text" v-model="name">
<h1 ref="stateDom">hh</h1>
</div>
</template>
<script lang="ts">
import { watchFile } from "fs";
import { stringify } from "querystring";
import { defineComponent,reactive,toRefs,computed,h,ref, customRef, onMounted,watchEffect } from "vue";
//这是防抖的
function Items(params:string,times:number=2000) {
let time:any=null;
return customRef((track,trigger)=>{
return {
get(){
console.log('00')
track();
return params;
},
set(newVal){
clearTimeout(time)
time=setTimeout(()=>{
params=newVal;
trigger();
// gge();
},times)
}
}
})
}
export default defineComponent({
name: "HelloWorld",
props: {
msg: String,
},
setup() {
const stateDom=ref(null)
onMounted(()=>{
console.log(stateDom.value)
// watchEffect(()=>{
// console.log(stateDom.value)
// })
})
return {
name,
stateDom
}
// return {
// ...render,
// ...sums,
// // ...Computed,
// ...toRefs(state),
// ...methods,
// };
},
});
</script>