Skip to content

Instantly share code, notes, and snippets.

@citrus
Created December 9, 2022 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save citrus/a62f5d080fea278ce8d0cdee61a7ba4c to your computer and use it in GitHub Desktop.
Save citrus/a62f5d080fea278ce8d0cdee61a7ba4c to your computer and use it in GitHub Desktop.
Add Pinia stores as global properties in Vue3 plugin with Typescript
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