UNPKG

tools-vue3

Version:
38 lines (36 loc) 953 B
import { ComponentInternalInstance } from 'vue'; /** * 同vue2中的minxins功能 * * 应用场景:多个父子组件引用同一个对象,当组件无任何引用时,对象自动销毁,下一次访问触发初始化 * * @example * * import { reactive } from 'vue' * import Minxins from 'tools-vue3' * const getIndex = () => { * const conf = reactive({ * name: 'index', * num: 1, * add: () => { * conf.num++ * } * }) * return conf * } * * export const index = () => Minxins.get('/main', getIndex) */ export default class Minxins { static map: Record<string, { value: any; refs: Set<ComponentInternalInstance>; }>; /** * 获取一个对象 * @param name 名称-全局唯一或者保证同一页面唯一存在 * @param fun 获取对象的方法-方法只能返回对象 * @returns 对象 */ static get<T>(name: string, fun: () => T): T; }