學習vuex 筆記

一 . vuex 是一個集中狀態管理工具vue

store 是集中管理數據的倉庫react

1. state 公共的數據vuex

2. getter 能夠看作是相似Vue的計算屬性異步

3. Mutations 能夠理解爲store中的 methods, 有兩個參數,第一個參數state, 第二個參數 payload,至關於react的 reducer函數

調用Mutations 中的回調函數,必定要用 this.$store.commit(type, payload) payload 是須要改變的數據,放到Mutations 中去處理數據工具

4. action 中能夠包含異步操做, Mutations 中絕對不容許出現異步;actions 中的回調函數的第一個參數是context, 是一個與 store 實例具備相同屬性和方法的對象,this

context調用的是mumations 裏的函數, context.commit( 'mutations 裏的方法',payload )spa

this.$store.dispatch(type, payload)對象

5. modules 將 store 分紅多個模塊,每一個模塊擁有本身的 state、mutation、action、getterget

相關文章
相關標籤/搜索