Axios GET 在 Safari 浏览器中不起作用

ste*_*nmd 5 safari vue.js axios vuejs2

我有一个简单的方法 getInfo() 请求,它在 vue 实例中的 created() 上调用。它从外部 api 获取数据并将其呈现在页面上。

created() {
    this.getInfo();
},
methods: {
    getInfo() {
        let vm  = this;
        let url = [my api url];
        axios.get(url)
          .then(response => {   
              console.log(response);
          })
          .catch(error => {
              console.log(error);
          })
    },
Run Code Online (Sandbox Code Playgroud)

该方法在 Chrome 中运行良好,但在 Safari (High Sierra, 10.13.2) 中完全被忽略。任何想法为什么会发生这种情况?没有控制台错误。

flp*_*ppv 8

对我来说,我发现,如果我添加/到我的终点,如结束/users/,而不是/users它在Safari浏览器,它是不是之前

  • 在拔了 6 天的头发后你才救了我 (5认同)

ste*_*nmd 6

好的能够解决问题,请参阅下面的代码。我重构了 axios 调用,并添加了一些新选项。关键是在 axios 调用中向 URL 添加一个缓存破坏者。Safari 不会自动执行此操作。谢谢大家的帮助。

    getInfo: function () {
        let vm  = this;
        let url = let url = [my api url];

        axios({
            method: 'get',
            url: url + '?nocache=' + new Date().getTime(), // Safari fix
            withCredentials: true
        })
          .then(response => {
              console.log(response)
          })
          .catch(error => {
              console.log(error);
          })
    },
Run Code Online (Sandbox Code Playgroud)