DEV Community

camo
camo

Posted on

How to get Pinia store inside the plugin function?

I have a helpers plugin which need to access Pinia store. The plugin have access to app object as all Vue plugins. I there a way to get Pinia store object from app instance inside the plugin? The plugin looks like

//import { useAppStore } from '@/store/app'  // This does not work. Pinia is not instantiated yet
//const appStore = useAppStore()

export default {
    install: (app) => {
        console.log(app)
        app.config.globalProperties.$translate = (translations, key) => {

            let result = translations[key] ? translations[key][0] : ''  // First item as default value or ''

        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)