problem description
the axios request is encapsulated in a function. When calling with other functions, it is always executed directly before the background request is executed because it is an asynchronous operation. As a result, the correct data cannot be obtained. Please ask your predecessors how to solve the problem. Vue rookie, thank you very much.
the environmental background of the problems and what methods you have tried
try to use aysnc and await, as shown below, but it is still unsuccessful
related codes
/ / Please paste the code text below (do not replace the code with pictures)
aysnc checkLogin () {
if (localStorage.getItem("access_token")){
//access_token
var postData = qs.stringify({
"access_token": localStorage.getItem("access_token"),
"refresh_token": localStorage.getItem("refresh_token"),
"username": localStorage.getItem("username")
})
axios({
method: "POST",
url: globalVar.remoteUrl + "/LoginCheck",
data: postData,
responseType: "json",
headers: {"Content-Type": "application/x-www-form-urlencoded"}
}).then((response) => {
if (response.data.code === 200){
//
this.$toast.success("")
}else if(response.data.code === 201){
// access_tokenrefresh_token
this.$toast.success("access_token")
}else if(response.data.code === 404){
// access_tokenrefresh_token
this.$toast.error("")
console.log("111")
}
})
}else {
this.$toast.error("")
}
},
async Login () {
await this.checkLogin();
console.log("222")
},
what result do you expect? What is the error message actually seen?
I think
console.log ("111")
then
console.log
the result is always negative