如何使用 axios 和代理获取 api 数据?

时间:2021-06-21 08:01:16

标签: vue.js axios

我正在尝试通过 axios 和 vuejs 从 api 获取一些简单的数据。

axios.get('https://www.coinspot.com.au/pubapi/v2/latest')
.then((response) => {
        console.log(response.data);
        console.log(response.status);
        console.log(response.statusText);
        console.log(response.headers);
        console.log(response.config);
 });

我收到以下错误:

GET http://localhost:8080/pubapi/v2/latest 404(未找到)

Uncaught (in promise) Error: Request failed with status code 404 at createError (createError.js?2d83:16) at settle (settle.js?467f:17) at XMLHttpRequest.handleLoad (xhr.js?b50d:62)

我可以在没有任何特殊情况的情况下让这些数据在邮递员中返回。如何让这些数据在我的 vuejs 应用程序中没有 cors 或 404 错误的情况下返回?

1 个答案:

答案 0 :(得分:-1)

尝试使用这个

   axios({
            method: 'get',
            url: 'https://www.coinspot.com.au/pubapi/v2/latest',
        }).then((response) => {
        console.log(response.data);
        console.log(response.status);
        console.log(response.statusText);
        console.log(response.headers);
        console.log(response.config);
 });