当获取首页产品列表时,返回数据length为0时取消发送请求

This commit is contained in:
clay
2022-12-29 09:48:45 +08:00
parent 0c3e8de069
commit 56bf10b47f
2 changed files with 10 additions and 10 deletions

View File

@@ -65,11 +65,8 @@
this.tagsArray = tag.split(',') this.tagsArray = tag.split(',')
item.tags = this.tagsArray[0] item.tags = this.tagsArray[0]
} }
this.$emit("getChild", tags.length);
// if (res.data.data.length == 0) {
// requestTask.abort()
// }
console.log(res);
// 为数据赋值:通过展开运算符的形式,进行新旧数据的拼接 // 为数据赋值:通过展开运算符的形式,进行新旧数据的拼接
this.productList = [...this.productList, ...res.data.data] this.productList = [...this.productList, ...res.data.data]

View File

@@ -38,7 +38,7 @@
</u-tabs> </u-tabs>
</view> </view>
<!-- 产品 --> <!-- 产品 -->
<products ref="getProducts"></products> <products ref="getProducts" @getChild="getChild()"></products>
</view> </view>
</view> </view>
</template> </template>
@@ -59,15 +59,14 @@
], ],
imgUrl: '', imgUrl: '',
swiperList: [], swiperList: [],
reachBottomLength: ''
} }
}, },
onReachBottom() { onReachBottom() {
// console.log('pageNum===', this.$refs.getProducts);
this.$refs.getProducts.pageNum += 1 this.$refs.getProducts.pageNum += 1
this.$refs.getProducts.getProducts() if (this.reachBottomLength !== 0) {
this.$refs.getProducts.getProducts()
//关闭下拉刷新 }
// uni.stopPullDownRefresh()
}, },
onLoad() { onLoad() {
this.getCategories() this.getCategories()
@@ -77,6 +76,10 @@
}, },
methods: { methods: {
//获取子组件的getProducts方法返回数据的length用于当length为0时取消发送请求
getChild(e) {
this.reachBottomLength = e
},
//获取一级分类 //获取一级分类
getCategories() { getCategories() {
this.$apiServe.getCategories().then(res => { this.$apiServe.getCategories().then(res => {