Files
hexo-blog/source/_posts/vue-resource-http请求在ios浏览器下的一个小坑.md
T
2020-11-24 17:45:32 +08:00

44 lines
903 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: vue-resource http请求在ios浏览器下的一个小坑
id: '69'
categories:
- 分享
tags:
- vue-resource
- http请求
- ios
date: 2016-07-05 18:41:00
---
``` js
new Vue({
el: 'body',
ready: function() {
this.$http.get('url', {
}).then(function(json) {
console.log(typeof json.data) //谷歌返回的是string,ios返回的是object
}, function(json) {
});
}
});
```
以上代码,在谷歌返回的是string,ios浏览器返回的是object, 所以通过JSON.parse()格式化json.data的时候,在ios浏览器下就报错了 通过使用vue-resource提供的json()方法解决 具体代码如下
``` js
new Vue({
el: 'body',
ready: function() {
this.$http.get('url', {
}).then(function(json) {
console.log(typeof json.json())
}, function(json) {
});
}
});
```