hookehuyr

新增全局变量创建和使用模块

1 +/**
2 + * 依赖注入命名集合
3 + */
4 +export const myInjectionKey = Symbol()
5 +export const fooInjectionKey = Symbol()
1 +import { provide, inject } from "vue";
2 +
3 +// const key = Symbol();
4 +
5 +/**
6 + * 创建全局变量
7 + * @param {*} context
8 + * @param {*} key
9 + */
10 +export function createContext(context, key) {
11 + provide(key, context)
12 +}
13 +/**
14 + * 使用全局变量
15 + * @param {*} key
16 + * @returns
17 + */
18 +export function useContext(key) {
19 + return inject(key)
20 +}