Created
December 9, 2022 17:41
-
-
Save citrus/a62f5d080fea278ce8d0cdee61a7ba4c to your computer and use it in GitHub Desktop.
Add Pinia stores as global properties in Vue3 plugin with Typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { App } from 'vue' | |
import { useAppStore, useAuthStore } from '@/stores' | |
declare module '@vue/runtime-core' { | |
interface ComponentCustomProperties { | |
$app: ReturnType<typeof useAppStore> | |
$auth: ReturnType<typeof useAuthStore> | |
} | |
} | |
export default { | |
install(app: App) { | |
app.config.globalProperties.$app = useAppStore() | |
app.config.globalProperties.$auth = useAuthStore() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment