【问题标题】:Failed to fetch vue.js [closed]无法获取 vue.js [关闭]
【发布时间】:2021-10-02 13:22:08
【问题描述】:

我将此代码添加到mounted()

mounted() {
fetch('http://127.0.0.1/logined')
    .then(
        function(response) {
          if (response.status !== 200) {
            console.log('Looks like there was a problem. Status Code: ' +
                response.status);
            return;
          }

          // Examine the text in the response
          response.json().then(function(data) {
            console.log(data);
          });
        }
    )
    .catch(function(err) {
      console.log('Fetch Error :-S', err);
    });
}

它没有修复,API 运行良好。 API 返回 {'result':'false'}

控制台日志

这个问题没有为我解决,我在另一台电脑上试过,但还是一样。 Axios 也不行,所以我改成 fetch。

【问题讨论】:

    标签: api vue.js get frontend fetch


    【解决方案1】:

    您的代码没有问题,您在屏幕截图中显示的错误表明您无法从 URL 获得任何结果。 您的浏览器似乎受 CORS 政策约束,这就是为什么它不起作用或者您使用 GET 而不是 POST

    【讨论】:

    • 谢谢,我的后端服务器有问题。
    • 我用 cors header 解决了!
    猜你喜欢
    • 2018-12-30
    • 2022-08-05
    • 2020-08-27
    • 2014-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-20
    • 2018-11-12
    相关资源
    最近更新 更多