Vue-resource: Vue resource不支持微信吗?

Created on 13 Aug 2016  ·  9Comments  ·  Source: pagekit/vue-resource

Vue 在微信中使用vue-resource,获取不了数据,用Jquery的Ajax正常。

Most helpful comment

let responseData = response.data
 if (typeof responseData === 'string') {
  responseData = JSON.parse(responseData)
}

在微信里面要对返回值做处理。

All 9 comments

一般浏览器对then方法响应两种写法均支持,如果在微信里,基于Vue的实例使用http,then方法的回调函数需要使用传统写法,Lambda写法微信不支持而且还会影响当前页面对Vux插件的调用,我刚刚发现的

传统写法

this.$http.get('/someUrl', [options]).then(function(response){
// 响应成功回调
}, function(response){
// 响应错误回调
});

Lambda写法

this.$http.get('/someUrl', [options]).then((response) => {
// 响应成功回调
}, (response) => {
// 响应错误回调
});

let responseData = response.data
 if (typeof responseData === 'string') {
  responseData = JSON.parse(responseData)
}

在微信里面要对返回值做处理。

只是安卓版本微信有这个 bug,返回的 data 没有解析成 Object,而是 String。因此需要做如上处理。

@hq5544 目前最新版微信貌似没有了这个问题, 刚才 alert 看了一下, 默认返回的JSON数据在微信的浏览器里 typeof 为 object

@Haojen 应该是我用的方法不对,我直接读取了 data,应该用 json() 方法。data 的话安卓就是 string。

@dp199313 和上述讨论的问题没有关系, 我的问题出在 vue 和 vue-resource 的版本不一致导致的, 你可以查看一下, 如果版本不一致, 请将 vue-resource 升级到和 vue 同版本

@dp199313 那看看是不是生命周期的问题?

fuck wechat

@dp199313 你有解决ios微信中不发请求的问题么,我这里也遇到了,而且只有个别的几个手机。

Was this page helpful?
0 / 5 - 0 ratings

Related issues

santigraviano picture santigraviano  ·  5Comments

gbhlwm picture gbhlwm  ·  5Comments

ramstein74 picture ramstein74  ·  3Comments

yozman picture yozman  ·  6Comments

christophwolff picture christophwolff  ·  6Comments