0

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":"''"}]

User.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();
    }
});

The error is : Unhandled promise rejection Error: Request failed with status code 404(…)

How can I fix it?

2 Answers 2

1

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.
})

Btw, make sure you are not requesting via CORS.

Sign up to request clarification or add additional context in comments.

Comments

0

In my case there was a spelling mistake in URL string. It is fixed after that correction.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.