亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vuex中store.commit和store.dispatch的區(qū)別及使用方法

 更新時(shí)間:2023年01月10日 10:12:49   作者:longzhoufeng  
這篇文章主要介紹了vuex中store.commit和store.dispatch的區(qū)別及使用方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

store.commit和store.dispatch的區(qū)別及使用

代碼示例:

this.$store.commit('loginStatus', 1);

this.$store.dispatch('isLogin', true);

規(guī)范的使用方式

// 以載荷形式
store.commit('increment',{
? amount: 10 ? //這是額外的參數(shù)
})

// 或者使用對(duì)象風(fēng)格的提交方式
store.commit({
? type: 'increment',
? amount: 10 ? //這是額外的參數(shù)
})

主要區(qū)別

dispatch:含有異步操作,數(shù)據(jù)提交至 actions ,可用于向后臺(tái)提交數(shù)據(jù)

this.$store.dispatch('isLogin', true);

commit:同步操作,數(shù)據(jù)提交至 mutations ,可用于讀取用戶(hù)信息寫(xiě)到緩存里

this.$store.commit('loginStatus', 1);

this.$store.dispatch() 與 this.$store.commit()

傳值給vuex的mutation改變state

commit: 同步操作

  • 存儲(chǔ)
this.$store.commit('changeValue',name)
  • 取值
this.$store.state.changeValue

dispatch: 異步操作

  • 存儲(chǔ)
this.$store.dispatch('getlists',name)
  • 取值
this.$store.getters.getlists

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論