<template>
? <input type="text" v-model="keyWrod" />
? <br />
? <span>{{ keyWrod }}</span>
</template>
<script>
import { customRef } from "vue";
export default {
? name: "App",
? setup() {
? ? let keyWrod = myRef("1231",500);
? ? function myRef(value,delay) {
? ? ? let timer;
? ? ? return customRef((track, trigger) => {
? ? ? ? return {
? ? ? ? ? get() {
? ? ? ? ? ? track();
? ? ? ? ? ? return value;
? ? ? ? ? },
? ? ? ? ? set(newValue) {
? ? ? ? ? ? clearTimeout(timer)
? ? ? ? ? ? timer = setTimeout(() => {
? ? ? ? ? ? ? value = newValue;
? ? ? ? ? ? ? trigger();
? ? ? ? ? ? }, delay);
? ? ? ? ? },
? ? ? ? };
? ? ? });
? ? }
? ? return {
? ? ? keyWrod,
? ? };
? },
};
</script>
<style>
</style>