在Vue的Vuex actions中如何实例化请求数据操作?
- 内容介绍
- 文章标签
- 相关推荐
本文共计220个文字,预计阅读时间需要1分钟。
我重新整理了您提供的代码片段,尽量简洁并符合您的要求:
javascript我废话不多说,直接上代码! + actions.js + getCertificationStatus(context, {vm: vm, type: type}) { + return new Promise((resolve, reject)=> { + axios.post('/realNameUtils/gotoStatusPage').then((res)=> { + context.commit('certificationSta'); + }); + }); + } +
我废话不多说了,直接上代码吧!
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'){//企业 }else if(type=='0'){//个人+企业 } 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中请求数据实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。
本文共计220个文字,预计阅读时间需要1分钟。
我重新整理了您提供的代码片段,尽量简洁并符合您的要求:
javascript我废话不多说,直接上代码! + actions.js + getCertificationStatus(context, {vm: vm, type: type}) { + return new Promise((resolve, reject)=> { + axios.post('/realNameUtils/gotoStatusPage').then((res)=> { + context.commit('certificationSta'); + }); + }); + } +
我废话不多说了,直接上代码吧!
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'){//企业 }else if(type=='0'){//个人+企业 } 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中请求数据实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

