账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    一个vuex state中的数据存取问题
    30
    0

    vuex的结构是这样的

    export default new Vuex.Store({
        state:{
            projects:[],
        },
        getters:{
            getAllProjs(state){
                return state.projects;
            },
            getProjectNamesById(state){
                return state.projects.map( proj => proj.name )
            }
        },
        mutations:{
            pushProjectsToStore(state,data){
                state.projects = data;
            },
        },
        actions:{
            pushProjectsToStore(){
                
            }
        }
    })

    父组件创建时

    beforeCreate(){
          this.$queryProject().then( res => this.$store.commit('pushProjectsToStore',res.data) )
      },

    子组件实例化时

    mounted () {
        //   获取项目信息
          this.projects = this.$store.getters.getAllProjs;
          this.projectNamesById = this.$store.getters.getProjectNamesById;
      },

    然后现在有个问题,getAllProjs执行时机是在pushProjectsToStore之前,所以拿不到数据,请问如何解决

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部