小编Sam*_*how的帖子

Vuex getters-properties使用vue-router时出现故障 - 它们无法被激活

首先,有 user.js,这是其中一个模块store.js

const state = {
  isLogin: false
}

const mutations = {
  login(state, userid){
    state.userid = userid;
  }
}

export default {
  state,
  mutations
}
Run Code Online (Sandbox Code Playgroud)

使用Vue-router,我创建了一个App Component,然后导入store.js.
然后是组件login.vue.以下是代码的一部分:

<script>    
export default {
  vuex: {
    actions: {
        login  // this action changes the state of
               // isLogin by dispatch `login` mutation
    }
  },

  methods: {
    btnClick(){
      // here calls the login action
    }
  }
} 
</script>
Run Code Online (Sandbox Code Playgroud)

我注意到该方法btnClick可以在这个组件中工作.它确实改变了store.state.user.isLogin.

但这是另一个a.vue听取 …

vue.js vue-router

5
推荐指数
1
解决办法
1437
查看次数

标签 统计

vue-router ×1

vue.js ×1