vuestic-ui
Version:
Vue 3 UI Framework
28 lines (27 loc) • 787 B
JavaScript
import { computed, getCurrentInstance, reactive } from "vue";
const getGlobalObject = () => {
const vm = getCurrentInstance();
const app = vm == null ? void 0 : vm.appContext.app;
const { globalProperties } = app.config;
if ("$vaGlobalVariable" in globalProperties) {
return globalProperties.$vaGlobalVariable;
}
globalProperties.$vaGlobalVariable = reactive({});
return globalProperties.$vaGlobalVariable;
};
const useAppGlobal = (key, defaultValue) => {
const globalObject = getGlobalObject();
if (!(key in globalObject)) {
globalObject[key] = defaultValue;
}
return computed({
get: () => globalObject[key],
set: (value) => {
globalObject[key] = value;
}
});
};
export {
useAppGlobal as u
};
//# sourceMappingURL=useAppGlobal.js.map