[{"id":1,"img":"https://images.unsplash.com/photo-1551446591-142875a901a1?w=640","name":"f1"},
{"id":2,"img":"https://images.unsplash.com/photo-1551446591-142875a901a1?w=640","name":"f2"},
{"id":3,"img":"https://images.unsplash.com/photo-1551446591-142875a901a1?w=640","name":"f3"}]
怎么把三条数据都显示在界面上?
这个数据是可以直接在小程序界面输出的,还有就是你的问题图片看不到,传图的时候换个行
更新内容
首先,你需要在这个地方
定义一个数组来存放你的数据,比如imglist:[]这样的,然后,你的接口请求也是错误的,既然api/values可以获取3条,就用这个接口,请求方法如下:
wx.request({
url: 'http://localhost/api/values',
success:function(res){
this.setData({
imglist:res.data
})
}
})
最后,在你的界面上使用这样的方式
<view wx:for="{{imglist}}">
<text>{{item.id}}</text>
<image src="{{item.img}}"></image>
<text>{{item.name}}</text>
</view>
以上就是全部过程
----------------更新----------
<view wx:for="{{imglist}}" data-id="{{item.id}}" bindtap="jump">
<text>{{item.id}}</text>
<image src="{{item.img}}"></image>
<text>{{item.name}}</text>
</view>
js部分:
jump:function(e){
var id = e.currentTarget.dataset.id
wx.navigateTo({
url:'跳转地址'+'?id='+id
})
}