![](/img/trans.png)
[英]Network Error when sending request to url from React Js using Axios
[英]Extracting token from the URL and sending a post request using Axios - Vue js
我一直在嘗試從http://test.com/confirm?token=MMsndiwhjidh...
提取令牌,然后將發布請求發送到另一台服務器。
我試過這個:
export default {
data() {
return {
confirmation : false,
somethingWrong: false
}
},
created: function() {
axios.post('/confirm', null, {
method: 'post',
params: {
token:this.$route.query.token
}
})
.then(function(res) {
console.log(res)
this.confirmation = true
})
.catch(function(error) {
console.log(error)
this.somethingWrong = true
})
}
}
我收到以下錯誤:
我想我無法正確提取令牌。
原因是您在 then / catch 塊中使用聲明性函數而不是箭頭函數。 this
不是指同一件事(這里, this
不是您的 Vue 組件)。
像這樣嘗試:
.then((res) => {
console.log(res)
this.confirmation = true
})
我不會嘗試自己解釋差異,因為網上有很多關於它的文章。 這是一個
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.