第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

vuex 中的getter action mutations commit 對應什么功能作用,

vuex 中的getter action mutations commit 對應什么功能作用,

汪汪一只貓 2018-08-30 17:37:35
如題vuex 中的getter action mutations commit 對應什么功能作用,
查看完整描述

2 回答

?
Alice_hhu

TA貢獻3條經(jīng)驗 獲得超1個贊

個人的一些粗淺總結,不完全正確,只是為了方便理解:

getter (相當于 store 的計算屬性,類似 vue 中的 computed,一般是對 state 中的屬性處理過后的屬性)

mutations (變化、方法、事件,類似 vue 中的 methods,可以對 state 中的屬性做一些處理等,不能直接調(diào)用,需要 commit 觸發(fā)調(diào)用)

action (用于?觸發(fā)?mutation,即進行 commit 動作,而?action 是通過 store.dispatch 方法來觸發(fā))

例如:

const?store?=?new?Vuex.Store({
????state?(){
??????return?{
????????data1:?0
????};
??},
??getters:?{
????getter1:?state?=>?{
??????return?state.data1?%?2?==?0???'偶數(shù)'?:?'奇數(shù)';
????}
??},
??mutations:?{?
????fun1?(state){
??????state.data1?++;
????}
??},
??actions:?{
??????action1?(context){
??????????context.commit('fun1');
??????}
??}
});
//?訪問?getters
console.log(store.getters.getter1);?//?偶數(shù)
//?分發(fā)?action
store.dispatch('action1');
console.log(store.getters.getter1);?//?奇數(shù)


查看完整回答
反對 回復 2018-10-09
  • 2 回答
  • 0 關注
  • 2068 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號