Firstly, there is user.js , which is one of the modules for store.js
const state = { isLogin: false } const mutations = { login(state, userid){ state.userid = userid; } } export default { state, mutations }
Using Vue-router, I created an application component and imported store.js .
And then comes the login.vue component. The following is part of the codes:
<script> export default { vuex: { actions: { login </script>
I noticed that the btnClick method may work in this component. He changed store.state.user.isLogin .
But here is another a.vue component that listens for isLogin state:
<template> ... <a v-if="isLogin" v-link="'#'"> ... </a> ... </template> <script> // import something export default { vuex: { getters: { isLogin: ({ user }) => user.isLogin } } } </script>
When btnClick switched to login.vue , isLogin changed. But it seems that although the isLogin getter in a.vue been changed, v-if in <a> could not be reactive because <a> not displayed.
I tried to check if store added to child components and the result passed. Also, I tried using computed instead of getters to listen for isLogin , and it also did not respond. when adding isLogin attributes to watch he could not watch.
And there is one thing I'm sure: Vue.use(Vuex) not missing.
I was wondering if this caused the Vue-router problem.
And nobody seemed to be asking questions about vuex using Vue-router ...
source share