Can't acess state from Vuex
-
Hello,
I am getting started with Quasar and been trying to integrate it with Vuex, but unfortunately, I am not able to access de state from …mapState nor $store.state. I get an error saying ‘[Vue warn]: Error in v-on handler: “TypeError: Cannot read property ‘loadedLogbook’ of undefined”’
Here is my store.js: https://pastebin.com/dXrThh8W
The component: https://pastebin.com/38j9cREk
logbook/index.js https://pastebin.com/PJczXLLm
State: https://pastebin.com/sfA2i1mm
Getters https://pastebin.com/bzwFyAcH
Mutation https://pastebin.com/UqFmGqp9
Actions https://pastebin.com/MCeNTxLAI am able to visualize the date from Vue Devtools as of this image:
-
@braganca mapState and mapGetters should be in
computed
not inmethods
. Please refer to vuex docs. -
@metalsadman I’m trying to use
quasar new store newModule
to add the Vuex manually today for my new Quasar project, it generates thenewModule
for me, but no theindex.js
config file, Could it do as the Quasar CLI works to generates theindex.js
config file also? -
@JackyLee the cli command just creates the module and files for you, you still have to register the module in your
src/store/index
module
object.
ie.//src/store/index.js import newModule from './newModule' ... modules: { newModule } ...
-
@metalsadman the problem is not such file
src/store/index
generated after run the command! If thequasar new store newModule
could add bothsrc/store/index
andsrc/store/module
will be be better. -
@JackyLee nope, its not automated. If you didnt include vuex when you were creating your project the first time, just create a new project running
quasar create
with vuex, then just copy the store/index.js file into your actual project.