【问题标题】:Vue: Unhandled promise rejection Error: Request failed with status code 404?Vue: Unhandled Promise Rejection Error: Request failed with status code 404?
【发布时间】:2018-06-19 03:40:33
【问题描述】:

我的API url是http://localhost:5000/api/user/list,数据显示为:

[{"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(...)

我该如何解决?

【问题讨论】:

    标签: vue.js


    【解决方案1】:

    您应该为您的 axios 请求注册一个处理程序。

    目前您正在使用设置参数作为处理程序。

    axios.get('http://localhost:5000/api/user/list').then(function (response) {
      // this is your handler.
    })
    

    顺便说一句,请确保您不是通过 CORS 请求。

    【讨论】:

      【解决方案2】:

      在我的例子中,URL 字符串中存在拼写错误。改正后就修复了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-07-10
        • 1970-01-01
        • 2021-10-18
        • 2021-07-09
        • 2023-02-09
        • 2022-08-19
        • 1970-01-01
        • 2021-10-01
        相关资源
        最近更新 更多