wxml:
<swiper interval="2000" indicator-dots="true" autoplay="true" circular="true"> <swiper-item v-for="(item,index) in dataList" :key="index"> <image style="width: 90%;margin-left: 5%;" :src="item.img"></image> </swiper-item> </swiper>
js
data() { return { dataList: [], } },
methods: { // 接口请求 fetchData() { uni.request({ url: '', // 接口地址 success: (res) => { console.log(res); this.dataList = res.data.banner;// 将接口返回的数据赋值给dataList }, fail: (error) => { console.log(error) } }) }, }, onLoad() { this.fetchData() // 在页面加载时调用fetchData方法获取数据 }