vuex的简单存值与取值

组件内取值

 computed: {    
    value() {
      return this.$store.state.userData.xxx;
    }
  },

组件内存值

methods: {  
     fn() {     
             this.$store.commit('setValue',xxx)       
          }           
    }

store的matution.js中

  setValue(state,xxx){
    state.userData.xxx= xxx;
  },

store的index.js中

const state = {
 
  userData: {
   
    "xxx":{}
  }
}

猜你喜欢

转载自blog.csdn.net/Web_J/article/details/85709362