vue中在vuex的actions中請求數(shù)據(jù)實例
更新時間:2019年11月08日 10:21:51 作者:Null_Bugs
今天小編就為大家分享一篇vue中在vuex的actions中請求數(shù)據(jù)實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
我廢話不多說了,直接上代碼吧!
actions.js getCertificationStatus(context, {vm:vm,type:type}){ return new Promise((resolve, reject) => { axios.post('/realNameUtils/gotoStatusPage') .then((res)=>{ context.commit('certificationStatus',res.data.content) if(type=='1'){//個人 }else if(type=='2'){//企業(yè) }else if(type=='0'){//個人+企業(yè) } resolve() }) }) } getters.js certificationStatus :(state)=>{ return state.certificationStatus } mutations.js var state = { certificationStatus: null } const mutations= { certificationStatus(state,data){ state.certificationStatus = data } } 組件: import {mapGetters} from 'vuex' computed: { ...mapGetters([ "certificationStatus" ]) } this.$store.dispatch('getCertificationStatus',{vm:this,type:'1'})
就是這樣就可以了 有疑問可以一起討論哦
以上這篇vue中在vuex的actions中請求數(shù)據(jù)實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
element-ui中el-cascader動態(tài)加載和默認值詳解
vue+elementUI項目中el-cascader級聯(lián)選擇器使用頻率非常高,下面這篇文章主要給大家介紹了關于element-ui中el-cascader動態(tài)加載和默認值的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2023-05-05基于Vue2的獨立構(gòu)建與運行時構(gòu)建的差別(詳解)
下面小編就為大家分享一篇基于Vue2的獨立構(gòu)建與運行時構(gòu)建的差別詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2017-12-12