useBoolean
优雅的管理 boolean 值
Demo
false
Usage
html
<template>
<div>
<p>{{ useBooleanState }}</p>
<button @click="useBooleanToggle">toggle</button>
<button @click="setTrue">setTrue</button>
<button @click="setFalse">setFalse</button>
</div>
</template>
<script lang="ts" setup>
import { useBoolean } from '@morehook/core'
const [useBooleanState, { toggle: useBooleanToggle, setTrue, setFalse }] =
useBoolean()
</script>
Type Declarations
typescript
/**
* toggle: 快捷切换正反值
* setTrue: 切换值为 true
* setFalse: 切换值为 false
*/
interface Actions {
toggle: () => void
setTrue: () => void
setFalse: () => void
}
/**
* 优雅的管理 boolean 值
* @param value 初始值 (默认为false)
* @returns 返回数组,[0] 是返回值,[1]是各个操作方法
*/
export declare function useBoolean(value?: boolean): [Ref<boolean>, Actions]