<template>
<div class="hello">
<div>value:{{ data }}</div>
<button @click="clear">关闭</button>
</div>
</template>
<script lang="ts">
import { ref } from 'vue';
import { useTimeout } from "v3hooks";
export default {
setup() {
const data = ref(1);
let delay = ref<null | number>(1000);
useTimeout(()=>{
data.value++
},delay)
const clear = ()=>{
delay.value = null;
};
return {
data,
clear
};
},
};
</script>
<script lang="ts">
import { useTimeout } from "v3hooks";
export default {
setup() {
useTimeout(()=>{
console.log(' 3s 后执行')
},3000)
},
};
</script>
const useTimeout: (
fn: Fn,
delay: number | Ref<number | undefined | null>
) => void;