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) 中完全被忽略。任何想法为什么会发生这种情况?没有控制台错误。
好的能够解决问题,请参阅下面的代码。我重构了 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)
| 归档时间: |
|
| 查看次数: |
9250 次 |
| 最近记录: |