useOnceWatch
useOnceWatch 跟watch类似,只触发一次监听,然后自动停止监听
基础用法
<template>
<div>Hello World! {{ count }}</div>
<button @click="count++">Add</button>
</template>
<script setup lang="ts">
import { ref } from "vue";
import { useOnceWatch } from "hooks-vue3";
const count = ref<number>(0);
useOnceWatch(count, () => {
console.log("只进来一次,然后自动停止监听");
});
</script>
API
useOnceWatch(count,callback,options);
参数TS类型
import type { WatchCallback, WatchOptions, WatchSource } from 'vue';
function useOnceWatch<T = any, Immediate extends Readonly<boolean> = false>(
source: T | WatchSource<T>,
cb: WatchCallback<T>,
options?: WatchOptions<Immediate>,
)
Last updated