首页 > 解决方案 > vuejs2 获取返回网络错误

问题描述

我正在尝试使用 vuejs2 访问 prestashop API

<script>
import axios from 'axios'

export default {
  data () {
    return {
      get: [],
      errors: []
    }
  },
  created () {
    axios({
      method: 'get',
      url: 'https://myprestashopsite.com/api/categories/?ws_key=J***************Z&filter[id_parent]=5&output_format=JSON'
    }).then(response => {
      this.get = response.data
    })
      .catch(e => {
        this.errors.push(e)
      })
  }
}

在 mozilla 的 Web 开发人员控制台中,我看到我的请求返回 200,其中包含响应中的数据。但我收到“错误:网络错误 app.js%20line%201266%20%3E%20eval:15:15”作为错误捕获。

我尝试使用另一个 API 并且它有效,所以我猜它来自 prestashop api。(prestashop 版本 1.7.3.0)

有没有办法来解决这个问题 ?

标签: apivuejs2prestashop

解决方案


问题似乎来自 axios。我不得不向服务器添加一条规则。

我在这个线程上找到了解决方案:

https://github.com/axios/axios/issues/853

如果我的不起作用,我没有在这个线程中尝试过其他解决方案。

如何添加规则:https ://enable-cors.org/server.html


推荐阅读