真是怪事,电脑平台调试没问题!
上了手机,API数据就不行!
求指教,谢谢!!
上图:
JS代码:
// pages/futrue/futrue.js
Page({
data:{},
onLoad:function(options){
// 页面初始化 options为页面跳转所带来的参数
var that=this;//这样是必须的,因为wx.request不支持this.setData的调用,不明白为什么
var URL=‘https://hq.sinajs.cn/list=CU0’
wx.request({
url:URL,
method:‘GET’,
success: function(res) {
console.log(res.data)
var str= res.data
console.log(‘str是:’+str)
var array0=str.split(’,’)
console.log(‘array0是:’+array0)
var array=array0.slice(1,18)
console.log(‘array是:’+array)
that.setData({
array:array
})
}
})
},
futrueRefress:function(event){
var that=this;//这样是必须的,因为wx.request不支持this.setData的调用,不明白为什么
var URL=‘https://hq.sinajs.cn/list=CU0’
wx.request({
url:URL,
method:‘GET’,
success: function(res) {
console.log(res.data)
var str= res.data
console.log(‘str是:’+str)
var array0=str.split(’,’)
console.log(‘array0是:’+array0)
var array=array0.slice(1,18)
console.log(‘array是:’+array)
that.setData({
array:array
})
}
})
},
onReady:function(){
// 页面渲染完成
},
onShow:function(){
// 页面显示
},
onHide:function(){
// 页面隐藏
},
onUnload:function(){
// 页面关闭
}
})
WXML代码
<view class=“page”>
<view class=“page__hd”>
<view class=“page__title”>沪铜</view>
<view class=“page__desc”>AU0沪铜连续</view>
</view>
<view class=“page__bd page__bd_spacing”>
<view class=“weui-flex”>
<view class=“weui-flex__item”><view class=“placeholder” style=“color:black”>{{array[16]}}</view></view>
</view>
<view class=“weui-flex”>
<view class=“weui-flex__item”><view class=“placeholder” style=“color:black”>今日最新</view></view>
<view class=“weui-flex__item”><view class=“placeholder” style=“color:black”>{{array[7]}}</view></view>
</view>
<view class=“weui-flex”>
<view class=“weui-flex__item”><view class=“placeholder” style=“color:black”>昨日收盘</view></view>
<view class=“weui-flex__item”><view class=“placeholder” style=“color:black”>{{array[4]}}</view></view>
</view>
</view>
<view class=“page__hd”>
<view class=“page__desc”>备注:进入页面自动载入最新价格,下拉可以手动刷新</view>
</view>
<button bindtap=“futrueRefress”>点击刷新</button>
</view>