0.1.0 • Published 2 years ago
@zdzz/hooks v0.1.0
vue hooks
业务中常用 vue hooks 函数
- useContext
import { InjectionKey, Ref } from "vue";
import { createContext, useContext } from "@zdzz/hooks";
export interface AppProviderContextProps {
prefixCls: Ref<string>;
isMobile: Ref<boolean>;
}
const key: InjectionKey<AppProviderContextProps> = Symbol();
export function createAppProviderContext(context: AppProviderContextProps) {
return createContext<AppProviderContextProps>(context, key);
}
export function useAppProviderContext() {
return useContext<AppProviderContextProps>(key);
}
- useEventListener
事件监听器
import { useEventListener } from "@zdzz/hooks";
useEventListener(window, "mousemove", (event) => {
// ...
});
- useImageViewer
import { useImageViewer } from "@zdzz/hooks";
const { view } = useImageViewer("a.png");
view();
const { view } = useImageViewer(["a.png", "b.png"]);
view(1);
- useRouteParams
import { useRouteParams } from "@zdzz/hooks";
const userId = useRouteParams("userId");
const userId = useRouteParams("userId", "-1"); // or with a default value
console.log(userId.value); // route.params.userId
userId.value = "100"; // router.replace({ params: { userId: '100' } })
- useRouteQuery
import { useRouteQuery } from "@zdzz/hooks";
import { useRouteQuery } from "@vueuse/router";
const search = useRouteQuery("search");
const search = useRouteQuery("search", "foo"); // or with a default value
console.log(search.value); // route.query.search
search.value = "foobar"; // router.replace({ query: { search: 'foobar' } })
- useToggle
import { useToggle } from "@zdzz/hooks";
const [value, toggle] = useToggle();
0.1.0
2 years ago
0.0.26
2 years ago
0.0.25
2 years ago
0.0.24
2 years ago
0.0.23
2 years ago
0.0.22
2 years ago
0.0.21
2 years ago
0.0.20
2 years ago
0.0.19
2 years ago
0.0.18
2 years ago
0.0.17
2 years ago
0.0.16
2 years ago
0.0.15
2 years ago
0.0.14
2 years ago
0.0.13
2 years ago
0.0.12
2 years ago
0.0.11
2 years ago
0.0.10
2 years ago
1.0.0
2 years ago
0.0.9
2 years ago
0.0.8
2 years ago
0.0.7
2 years ago
0.0.6
2 years ago
0.0.5
2 years ago
0.0.3
2 years ago
0.0.2
2 years ago
0.0.1
2 years ago