zhengyiming
2025-04-17 60b9c62a3165f304a933cbac304ac3d43a24f722
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { ToRefs } from 'vue';
 
export function useVModel<P extends object, K extends keyof P>(
  props: P,
  key: K,
  emit: (name: string, ...args: any[]) => void
) {
  return computed({
    get() {
      return props[key];
    },
    set(v: any) {
      emit(`update:${key!.toString()}`, v);
    },
  });
}
 
export function useVModels<P extends object>(
  props: P,
  emit: (name: string, ...args: any[]) => void
): ToRefs<P> {
  const ret: any = {};
 
  for (const key in props) {
    ret[key] = useVModel(props, key, emit);
  }
  return ret;
}
 
export function useCanGoBack() {
  const router = useRouter();
 
  function checkCanGoBack() {
    return router.options.history.state.back !== null;
  }
  const isCanGoBack = computed(() => checkCanGoBack());
  return {
    isCanGoBack,
  };
}