wx.request请求数据,本地获取失败
做了一个数据请求测试, 数据拿到了,为什么在模板获取失败呢?
wxml:
<view class="lists-gys" style="background:#ffffff"> <!--列表模版 begin--> <template name="gys"> <view class="gyssp-name">{{week}}</view> </template> <!--列表模版 end--> <!--循环输出列表 begin--> <view wx:for="{{Industry}}" class="lists-gys-img"> <template is="gys" data="{{...item}}" /> </view> <!--循环输出列表 end--> </view> |
js:
Page({data:{Industry:[]},, onLoad: function (res) { var that = this //调用应用实例的方法获取全局数据 app.getUserInfo(function (userInfo) { //更新数据 that.setData({ userInfo: userInfo }) }) wx.request({ //上线的话必须是https,没有appId的本地请求貌似不受影响 url: 'http://v.juhe.cn/weather/index?format=2&cityname=%E8%8B%8F%E5%B7%9E&key=4c2de5dc11360a676cee9ea8642d36e7', data: {}, method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT // header: {}, // 设置请求的 header success: function (res) { console.log(res.data.result), console.log(res.data.result.future), console.log(res.data.result.future[0].week),//获取到数据了:星期五 console.log(res.data.result.today) that.setData({ Industry: res.data.result.future }) }, fail: function () { // fail }, complete: function () { // complete } }) }}) |
