mirror of
https://github.com/chansee97/nova-admin.git
synced 2025-04-05 19:41:59 +08:00
16 lines
288 B
TypeScript
16 lines
288 B
TypeScript
/**
|
|
* Apply default value to a ref.
|
|
*/
|
|
export function useDefault<T>(defaultValue: T): Ref<T> {
|
|
const source: Ref<T | undefined | null> = ref()
|
|
|
|
return computed({
|
|
get() {
|
|
return source.value ?? defaultValue
|
|
},
|
|
set(value) {
|
|
source.value = value
|
|
},
|
|
})
|
|
}
|