js文件:
onLoad: function () {
var that = this;
wx.request({
url: ‘https:/xxxxx’,//上线的话必须是https,没有appId的本地请求貌似不受影响
method: ‘POST’, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
// header: {}, // 设置请求的 header
dataType:‘json’,
success: function (res) {
console.log(res.data);
that.setData({
sz:res.data
})
},
});
请求到的数据:[{“image”:"\/static\/index\/picture\/banner1.jpg"},{“image”:"\/static\/index\/picture\/banner2.jpg"},{“image”:"\/static\/index\/picture\/banner3.jpg"}]
xml文件:
<swiper class=“swiper” indicator-dots=“true” autoplay=“true” interval=“5000” duration=“1000”>
<block wx:for="{{sz}}" wx:key=‘key’>
<swiper-item>
<image src=“https:/xxxx/{{item.image}}” class=“slide-image” mode=“aspectFill”/>
</swiper-item>
</block>
</swiper>