Files
admin-sjzx/src/utils/useCurrentInstance.ts

14 lines
453 B
TypeScript
Raw Normal View History

2024-02-19 13:44:32 +08:00
import { getCurrentInstance } from 'vue'
import type { ComponentInternalInstance } from 'vue'
export default function useCurrentInstance() {
if (!getCurrentInstance()) {
throw new Error('useCurrentInstance() can only be used inside setup() or functional components!')
}
const { appContext } = getCurrentInstance() as ComponentInternalInstance
const proxy = appContext.config.globalProperties
return {
proxy,
}
}