Skip to content

useWatchSwitch

useWatchSwitch(source, options): void

监听状态,根据状态值切换开关状态

参数

NameTypeDefault valueDescription
sourceFunction | Ref<any>undefined需要监听的状态,支持传入 ref 和监听函数
optionsObjectundefined
options.closeundefined | () => voidnoop关闭
options.immediatebooleantrue立即执行
options.openundefined | () => voidnoop打开

返回值

void

示例

ts
useWatchSwitch(() => props.visible, {
  open: () => nextTick(() => instance.refs.popup.open()),
  close: () => nextTick(() => instance.refs.popup.close()),
})

源码

use-watch-switch.js