更新
This commit is contained in:
1 parent
5cd551a08e
commit
40cde540d6
33 files changed
+547
-319
No files matched your search
@@ -1,42 +1,43 @@
|
||||
---
|
||||
title: vue-resource http请求在ios浏览器下的一个小坑
|
||||
tags: []
|
||||
id: '69'
|
||||
categories:
|
||||
- - 分享
|
||||
- 分享
|
||||
tags:
|
||||
- vue-resource
|
||||
- http请求
|
||||
- ios
|
||||
date: 2016-07-05 18:41:00
|
||||
---
|
||||
|
||||
```js
|
||||
|
||||
``` js
|
||||
new Vue({
|
||||
el: 'body',
|
||||
ready:function(){
|
||||
this.$http.get('url',{
|
||||
el: 'body',
|
||||
ready: function() {
|
||||
this.$http.get('url', {
|
||||
|
||||
}).then(function(json){
|
||||
console.log( typeof json.data ) //谷歌返回的是string,ios返回的是object
|
||||
},function(json){
|
||||
}).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
|
||||
|
||||
``` js
|
||||
new Vue({
|
||||
el: 'body',
|
||||
ready:function(){
|
||||
this.$http.get('url',{
|
||||
el: 'body',
|
||||
ready: function() {
|
||||
this.$http.get('url', {
|
||||
|
||||
}).then(function(json){
|
||||
console.log( typeof json.json())
|
||||
},function(json){
|
||||
}).then(function(json) {
|
||||
console.log(typeof json.json())
|
||||
}, function(json) {
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
```
|
||||
```
|
||||
Reference in new issue
Block a user