0.1.0 • Published 11 months ago

@zdzz/hooks v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

vue hooks

业务中常用 vue hooks 函数

  1. 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);
}
  1. useEventListener

事件监听器

import { useEventListener } from "@zdzz/hooks";

useEventListener(window, "mousemove", (event) => {
  // ...
});
  1. useImageViewer
import { useImageViewer } from "@zdzz/hooks";

const { view } = useImageViewer("a.png");
view();

const { view } = useImageViewer(["a.png", "b.png"]);
view(1);
  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' } })
  1. 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' } })
  1. useToggle
import { useToggle } from "@zdzz/hooks";

const [value, toggle] = useToggle();
0.1.0

11 months ago

0.0.26

12 months ago

0.0.25

1 year ago

0.0.24

1 year ago

0.0.23

1 year ago

0.0.22

1 year ago

0.0.21

1 year ago

0.0.20

1 year ago

0.0.19

1 year ago

0.0.18

1 year ago

0.0.17

1 year ago

0.0.16

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

1.0.0

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago