Answer the question
In order to leave comments, you need to log in
Why is the vuex store unavailable?
Good afternoon. I found a tutorial on how to create an online chat on Nuxt on the net, but there was a problem. When I tried to hide the page from unauthorized users, I got this error "cannot convert undefine or null to object"
Here is the store code:
export const store = () => ({
user: {}
})
export const mutations = {
setUser(state, user) {
state.user = user
}
}
export default function({store, redirect}) {
if(!Object.keys(store.state.user).length) {
redirect('/?message=noUser')
}
}
<template>
<h1>Wellcome {{ user.name }}</h1>
</template>
<script>
import {mapState} from 'vuex'
export default {
middleware: ['chat'],
computed: mapState(['user'])
}
</script>
Answer the question
In order to leave comments, you need to log in
Incorrect named export in storage module: state should be instead of store.
export const state = () => ({
user: {}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question