使用vuex實現組件間傳值


 

1.state中的數據獲取時使用 this.$store.state.xxx;
2.修改state中的數據必須通過 mutations 中提供的方法,調用方法使用 this.$store.commit('方法名稱', 唯一參數),要傳遞多個參數可使用對象;
3.如果對外提供 state 中的數據時需要對數據進行包裝,可使用 getters,方法為: this.$store.getters.xxx
let store = new Vuex.Store({
    state: {
        theUrl: {},
        count: 0,
    },
    mutations: {
        increment(state, obj) {
        state.count += (obj.a + obj.d)
         }   
     },
    getters: {
        optCount: function (state) {
        return '當前最新的count值是:' + state.count
        }
  },
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM