mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
1.2 KiB
1.2 KiB
useToggle
Intro
Used to switch between true
and false
.
Usage
Basic Usage
import { useToggle } from '@vant/use';
export default {
setup() {
const [state, toggle] = useToggle();
toggle(true);
console.log(state.value); // -> true
toggle(false);
console.log(state.value); // -> false
toggle();
console.log(state.value); // -> true
},
};
Default Value
import { useToggle } from '@vant/use';
export default {
setup() {
const [state, toggle] = useToggle(true);
console.log(state.value); // -> true
},
};
API
Type Declarations
function useToggle(
defaultValue: boolean
): [Ref<boolean>, (newValue: boolean) => void];
Params
Name | Description | Type | Default Value |
---|---|---|---|
defaultValue | Default value | boolean | false |
Return Value
Name | Description | Type |
---|---|---|
state | State | Ref<boolean> |
toggle | Function to switch state | (newValue?: boolean) => void |