Nuxt.js: get vuex store without a context or a vue component

Created on 8 Jun 2017  路  4Comments  路  Source: nuxt/nuxt.js

How I can get the store in javascript modules that doesn't have access to the nuxt context or a vue component?

import Store from '~store'
// or
const store = require('~store')

console.log(store)
// { createStore: [Getter] }

is not working any more in the latest versions.

This question is available on Nuxt.js community (#c736)
help-wanted

Most helpful comment

Hi @LowM4N

The ~store alias is going to be removed, with 1.0, the plugins now receives the context :confetti_ball:

plugins/my-plugin.js

export default ({ store }) => {
  // here you have store!
}

Keep in mind that nuxt.js call the methods of the plugins without waiting for their answer so they cannot be asynchronous (middleware are there for that).

Demo: https://complex-secretary.glitch.me/
Code: https://glitch.com/edit/#!/complex-secretary?path=plugins/test-store.js:3:59

:smile:

All 4 comments

Hi @LowM4N

The ~store alias is going to be removed, with 1.0, the plugins now receives the context :confetti_ball:

plugins/my-plugin.js

export default ({ store }) => {
  // here you have store!
}

Keep in mind that nuxt.js call the methods of the plugins without waiting for their answer so they cannot be asynchronous (middleware are there for that).

Demo: https://complex-secretary.glitch.me/
Code: https://glitch.com/edit/#!/complex-secretary?path=plugins/test-store.js:3:59

:smile:

I've a problem with this modification...

I cannot get state from store in context...

https://github.com/nuxt/nuxt.js/issues/3114

@Atinux And to use the store inside a class? Like:

import { Model as BaseModel } from 'vue-api-query'

export default class Model extends BaseModel {
...
}

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nassimbenkirane picture nassimbenkirane  路  3Comments

uptownhr picture uptownhr  路  3Comments

o-alexandrov picture o-alexandrov  路  3Comments

vadimsg picture vadimsg  路  3Comments

gary149 picture gary149  路  3Comments