Why vuex $store gives "undefined"?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
56 views
Hi. So I resumed training Vue.JS and then just issue:

I have a file route, which spells out all the ranting and check for authorization:
import Vue from 'vue' import VueRouter from 'vue-router' import Meta from 'vue-meta' Vue.use(VueRouter) Vue.use(Meta) /** * For users * @constructor */ const Home = () => import('../components/home.vue') /** * For guests * @constructor */ const Welcome = () => import('../components/welcome.vue') /** * Error page * @constructor */ const NotFound = () => import('../components/errors/NotFound.vue') const router = new VueRouter({ mode: 'history', routes: [ /* Neutral */ { path: '/', name: 'home', component: Home, meta: {isAuth: true} }, { path: '/welcome', name: 'welcome', component: Welcome, meta: {guest: true} }, { /* 404 - Page not found */ path: '/404', name: 'notfound', component: NotFound }, { path: '*', redirect: '/404' } ], linkActiveClass: ", linkExactActiveClass:" }); console.log(this.$store) // Try to get at least something // It will check for authorization and issuance of the necessary routes // router.beforeEach( // (to, from, next) => { // if(to.matched.some(record => record.meta.isGuest)){ // if(this.$store.state.auth.check){ // next({ // path: '/' // }) // } else next() // }else if(to.matched.some(record => record.meta.isAuth)){ // if(!this.$store.state.auth.check){ // next({ // path: '/auth/login' // }) // }else{ // next() // } // } else next() // } // ) export default router


He, in fact, Vuex:
import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) const state = { auth: { check: false, user: {} } } export default new Vuex.Store({ strict: process.env.NODE_ENV !== 'production', state getters: { /** * Check user authorization * @param state * @returns {boolean} */ authCheck: (state) => { if(state.auth.check){ return true } return false } }, mutations: {}, })


And when I want to get data getter in the file, the route can not - writes undefined. Here, for example, in the home file.vue, created() I have the data displayed. I've been trying to get the values (how long ago I had someone advised):
Vue.store Vue.$store this.store this.$store


In advance, thank you for the help!
by | 56 views

1 Answer

0 like 0 dislike
Because you're nowhere in the router pointed to him where to take this store
Import it separately
by

Related questions

0 like 0 dislike
1 answer
asked Jun 2, 2019 by BonBonSlick
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked Jun 14, 2019 by AndrewRusinas
110,608 questions
257,187 answers
0 comments
40,796 users