Axios GET 在 Safari 浏览器中不起作用
Axios GET not working in Safari browser
我有一个在 vue 实例中的 created() 上调用的简单方法 getInfo() 请求。它从外部抓取数据 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);
})
},
该方法在 Chrome 中运行良好,但在 Safari(High Sierra,10.13.2)中完全被忽略。为什么会发生这种情况的任何想法?没有控制台错误。
正如@Bert 在他的评论中提到的,Safari 浏览器尚不支持方法快捷方式。
尝试这样的事情,
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);
})
},
好的,问题解决了,请看下面的代码。我重构了 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);
})
},
对我来说,我发现如果我将 /
添加到端点的末尾,例如/users/
而不是 /users
它可以在 Safari 中使用,而在它之前没有
我有一个在 vue 实例中的 created() 上调用的简单方法 getInfo() 请求。它从外部抓取数据 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);
})
},
该方法在 Chrome 中运行良好,但在 Safari(High Sierra,10.13.2)中完全被忽略。为什么会发生这种情况的任何想法?没有控制台错误。
正如@Bert 在他的评论中提到的,Safari 浏览器尚不支持方法快捷方式。
尝试这样的事情,
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);
})
},
好的,问题解决了,请看下面的代码。我重构了 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);
})
},
对我来说,我发现如果我将 /
添加到端点的末尾,例如/users/
而不是 /users
它可以在 Safari 中使用,而在它之前没有