watchImmediate
watch 带有 {immediate: true} 的简写。
用法
类似于 watch,但带有 { immediate: true }。
import { watchImmediate } from '@vueuse/core'
const obj = ref('vue-use')
// changing the value from some external store/composables
obj.value = 'VueUse'
watchImmediate(obj, (updated) => {
console.log(updated) // Console.log will be logged twice
})
类型声明
export declare function watchImmediate<
T extends Readonly<WatchSource<unknown>[]>,
>(
source: [...T],
cb: WatchCallback<MapSources<T>, MapOldSources<T, true>>,
options?: Omit<WatchOptions<true>, "immediate">,
): WatchStopHandle
export declare function watchImmediate<T>(
source: WatchSource<T>,
cb: WatchCallback<T, T | undefined>,
options?: Omit<WatchOptions<true>, "immediate">,
): WatchStopHandle
export declare function watchImmediate<T extends object>(
source: T,
cb: WatchCallback<T, T | undefined>,
options?: Omit<WatchOptions<true>, "immediate">,
): WatchStopHandle