Vue:未处理的承诺拒绝错误:请求失败,状态码为 404? [英] Vue: Unhandled promise rejection Error: Request failed with status code 404?
本文介绍了Vue:未处理的承诺拒绝错误:请求失败,状态码为 404?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 API 网址是 http://localhost:5000/api/user/list,数据显示为:
My API url is http://localhost:5000/api/user/list, data shows as:
[{"Id":1,"name":"Michael","pwd":"123456","age":0,"birth":"2018-01-05","addr":"''"},{"Id":2,"name":"Jack","pwd":"123512616","age":0,"birth":"2018-01-05","addr":"''"}]
用户.vue
import axios from 'axios';
export default {
data() {
return {
filters: {
name: ''
},
loading: false,
users: [
]
}
},
methods: {
getUser: function () {
axios.get('http://localhost:5000/api/user/list', function (data) {
this.$set('users', data);
})
}
},
mounted() {
this.getUser();
}
});
错误是:未处理的承诺拒绝错误:请求失败,状态码为 404(...)
The error is : Unhandled promise rejection Error: Request failed with status code 404(…)
我该如何解决?
推荐答案
你应该为你的 axios 请求注册一个处理程序.
You should register a handler for your axios request.
目前您正在使用设置参数作为处理程序.
Currently you are using settings argument as a handler.
axios.get('http://localhost:5000/api/user/list').then(function (response) {
// this is your handler.
})
顺便说一句,请确保您不是通过 CORS 请求.
Btw, make sure you are not requesting via CORS.
这篇关于Vue:未处理的承诺拒绝错误:请求失败,状态码为 404?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文