problem description
The mutations ofvuex uses axios to request data. According to the returned value, you can judge to jump to different pages and report an error
.the environmental background of the problems and what methods you have tried
this requirement is that there is an API that needs to be used on multiple pages, and there are a lot of judgments. I just want to put it into vuex to make multiple calls, but jump to report an error in mutations
. I tried to use
this.$store.dispatch ("getCertificationStatus",this.$router)
to pass this.$router, but I still couldn"t
change
call
methods: {
state : function(){
this.$store.dispatch("getCertificationStatus",this)
}
store.js
getCertificationStatus(state,vm){
return new Promise((resolve, reject) => {
axios.post("/realNameUtils/gotoStatusPage")
.then((res)=>{
if(res.data.content == "NOT_REALNAME"){
vm.$router.push({path:"/user/info"})//
}
related codes
/ / Please paste the code text below (do not replace the code with pictures)
getCertificationStatus(state){
return new Promise((resolve, reject) => {
axios.post("/realNameUtils/gotoStatusPage")
.then((res)=>{
if(res.data.content == "NOT_REALNAME"){
this.$router.push({path:"/user/info"})//
}
if(res.data.content == "NATURAL_SUBMIT"){
this.$router.push({path:"/user/review"})//
}
if(res.data.content == "NATURAL_BASEINFO_FAILED"){
this.$router.push({path:"/user/fail"})//
}
if(res.data.content == "NATURAL_BASEINFO_SUCCESS"){
this.$router.push({path:"/user/waitFor"})//
}
if(res.data.content == "NATURAL_PAY_FAILED"){
this.$router.push({path:"/user/cardreFill"})//fail
}
if(res.data.content == "NATURAL_PAY_SUCCESS"){
this.$router.push({path:"/user/firmMoney"})//OK3
}
if(res.data.content == "NATURAL_BANK_SUCCESS"){
this.$router.push({path:"/user/success"})//
}
if(res.data.content == "NATURAL_BANK_FAILED"){
this.$router.push({path:"/user/cardFail"})//
}
}
})
}
what result do you expect? What is the error message actually seen?