Inject data map into all stores #1278
Answered
by
posva
bobmcallan
asked this question in
Help and Questions
-
I'd like to add/inject a data map object into every store. Currently using the following: export const DATA_DEFAULTS = {
data: new Map(),
total: 0,
size: 25,
page: 0,
loading: false,
}
export function dataPlugin({ store, options }) {
store.$state = () => Object.assign({}, store.$state, DATA_DEFAULTS)
} The map is not created in each store? How should I inject/create. |
Beta Was this translation helpful? Give feedback.
Answered by
posva
May 12, 2022
Replies: 2 comments 4 replies
-
follow the docs https://pinia.vuejs.org/core-concepts/plugins.html#augmenting-a-store const pinia = createPinia();
pinia.use(({ store }) => {
store.$router = markRaw(router);
store.page = 10;
}); |
Beta Was this translation helpful? Give feedback.
2 replies
-
You need to assign directly to the Object.assign(store.$state, DATA_DEFAULTS)
store.data = toRef(store.$state, 'data') See https://pinia.vuejs.org/core-concepts/plugins.html#adding-new-state |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
bobmcallan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to assign directly to the
$state
and then add refs of each added property like shown in docs:See https://pinia.vuejs.org/core-concepts/plugins.html#adding-new-state