翻页的时候先显示了缓存
来源:5-14 切换选项卡懒加载数据

蒋犇犇
2020-05-24
我翻页的时候,显示的是当前页面,翻页完成后才显示新的数据.
下面是swiper组件的代码
<template>
<swiper class="swiper-layout" @change="change" :current="tabIndex">
<swiper-item class="swiper-layout-item" v-for="(item, index) in tabList.length"
:key="index">
<scroll-list class="scroll-layout">
<list-card v-for="(item,index) in listCatchData[tabIndex]" :itemData="item" :key="index"></list-card>
</scroll-list>
</swiper-item>
</swiper>
</template>
<script>
export default {
props: {
tabList: {
type: Array,
default(){
return []
}
},
tabIndex: {
type: Number,
default: 0
}
},
data() {
return {
listCatchData:[]
};
},
watch:{
tabList(newTabList){
if(newTabList.length === 0){
return
}
this.getList(this.tabIndex)
}
},
methods: {
change(e) {
//组件通知页面引用的@swiperChange方法
let current = e.detail.current
this.$emit('swiperChange', current);
if(!this.listCatchData[current] || this.listCatchData[current].length===0){
this.getList(current)
}
},
getList(index){
this.$api.getList({
name: this.tabList[index].name
}).then((data)=>{
this.$set(this.listCatchData,index,data)
})
},
}
};
</script>
<style lang="scss">
// swiper和scroll-list的高度确定就可以滑动
.swiper-layout {
height: 100%;
.swiper-layout-item {
.scroll-layout {
height: 100%;
}
}
}
</style>
写回答
1回答
-
注意 change 事件中的this.$emit('swiperChange', current); 是在调用页面 改变了 tabIndex, 看一下你的代码,是否有这一步的操作
032020-05-26
相似问题