【发布时间】:2019-11-20 09:38:01
【问题描述】:
我正在构建一个智能家居应用程序。我在将 PUT 请求发送到我的 rest api 时遇到问题(我用烧瓶构建它),但是当我尝试发送请求时,它给了我 HTTP 400 错误((未捕获(承诺中)错误:请求失败,状态码为 400))。你能帮帮我吗?
import axios from 'axios';
export default {
data: function() {
return {
value: 0,
lampName: 'Kitchen',
};
},
mounted () {
axios
.get("http://127.0.0.1:5000/lamp/" + this.$route.params.id)
.then(response => (this.value = response.data))
},
methods: {
updateValue () {
axios
.put('http://127.0.0.1:5000/lamp/' + this.$route.params.id,
{value: this.value},
{headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
})
}
}
}
【问题讨论】:
-
试试 .catch(error => console.log(error))
-
感谢您的回答,但它仍然不起作用,并且不会在控制台中打印更多信息。