I am getting started with nuxtjs and vuex. I just encountered an issue accessing a combined injected plugin function from a getter. E.g.:
nuxt.config.js
...
plugins: [
'~/plugins/myplugin.js'
],
...
~/plugins/myplugin.js
function doSomething(string) {
console.log("done something: " + string)
}
export default ({ app }, inject) => {
inject('doSomething', (string) => doSomething(string))
}
~/store/index.js
export const actions = {
someAction({commit}) {
this.$doSomething("Called from Action") // works
}
}
export const getters = {
someGetter: state => {
this.$doSomething("Called from Getter") // throws error
}
}
The code works for the action someAction
but the call in getter someGetter
will result in a error suggesting this
is undefined.
The nuxt documentation only shows examples for accessing injected plugin functions from mutations and actions but does not explicitly mention that getters can not access plugin functions. Is this even possible in nuxt or is there a good reason not to call a plugin method in a getter? Any help appreciated.