feat: bubble组件封装

This commit is contained in:
renxiaodong
2025-08-21 00:24:36 +08:00
parent 6e3158cdb4
commit 64621d9add
17 changed files with 911 additions and 5 deletions

View File

@ -0,0 +1,15 @@
/*
* @Author: RenXiaoDong
* @Date: 2025-08-20 23:12:14
*/
import { ref } from 'vue';
export function useEventCallback<T>(handler?: (value: T) => void): (value: T) => void {
const callbackRef = ref(handler);
const fn = ref((value: T) => {
callbackRef.value && callbackRef.value(value);
});
callbackRef.value = handler;
return fn.value;
}

21
src/hooks/useState.ts Normal file
View File

@ -0,0 +1,21 @@
/*
* @Author: RenXiaoDong
* @Date: 2025-08-20 23:14:22
*/
import type { Ref } from 'vue';
import { ref } from 'vue';
export default function useState<T, R = Ref<T>>(
defaultStateValue?: T | (() => T),
): [R, (val: T) => void] {
const initValue: T =
typeof defaultStateValue === 'function' ? (defaultStateValue as any)() : defaultStateValue;
const innerValue = ref(initValue) as Ref<T>;
function triggerChange(newValue: T) {
innerValue.value = newValue;
}
return [innerValue as unknown as R, triggerChange];
}