Guidance for integration of Typescript and Vuex 4 / Pinia 2
See original GitHub issueIs your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I’m always frustrated when […]
I’m needing some guidance on how to use Typescript with Vuex v4 and Quasar 2. Vuex v4 recommends registering Typescript typed Vuex stores using this code …
However Quasar 2 appears to registers the root store for you and unlike Quasar 1.x there’s no main.ts
or main.js anymore to apply app.use()
before the app is mounted. I suspect that registering in a boot file is too late as the root store has already been created for you.
// main.ts
import { createApp } from 'vue'
import { store, key } from './store'
const app = createApp({ ... })
// pass the injection key
app.use(store, key) // <<< Probably too late to do this in a boot script. Unclear if this is required *per store* or root store only??
app.mount('#app')
Describe the solution you’d like A clear and concise description of what you want to happen.
Perhaps an update on the Quasar 2.x Vuex page with advice for Vuex 4 and Typescript.
Describe alternatives you’ve considered A clear and concise description of any alternative solutions or features you’ve considered.
I also tried to use pinia
with a boot script but hit other issues with Quasar 2. The pinia
v2 stores lost my getters and actions for some reason - possibly related to conflicts with existing vuex store registration done by Quasar??. I ended up tossing the pinia
stores and trying Vuex 4 only to hit another problem. I noted pinia
had special instructions for Nuxt so probably Quasar needs some custom code to work with pinia
v2 perhaps done in collaboration with the pinia
team.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
Hi, i successfuly integrated pinia in quasar 2!!!
in quasar.conf.js add pinia boot file
in /src/boot, create a pinia.ts
create a store file: /src/stores/user.ts
use the store in any vue component/page/layout:
and you can also use in routes to protect with router guards, example /src/router/index.ts
and /src/router/routes.ts
First-party Pinia support is released in @quasar/app-vite-v1.0.0-beta.1 and @quasar/app-webpack-v3.4.0. It’s been available for almost a month now, so I am closing this issue. Thanks for the feature request!