开始
话题详情页的,上拉加载
参考动态页的关注。底部也有上拉加载。
复制组件的引用
import loadMore from '@/components/common/load-more.vue';
<!-- 上拉加载 -->
<load-more :loadtext="guanzhu.loadtext"></load-more>
H5端-wjw
在我的H5端 要想显示最底部,必须要动态的计算出总的高度来,然后通过滚动条滚动到最底部。
给最外层的这个topic-detail-list加上 动态计算出来的高度。
:style="{height: swiperheight+'px'}"
swiperheight: 500,
onLoad() {
uni.getSystemInfo({
success: (res) => {
console.log('当前window高度和窗口高度');
console.log(res.windowHeight);
console.log(res.screenHeight);
let height = res.windowHeight - uni.upx2px(100)
this.swiperheight = height;
}
});
},
继续
页面监听加载更多的事件
页面上拉触底事件的处理函数
复制news页面的loadMore方法
// 上拉加载
loadmore() {
if (this.guanzhu.loadtext != "上拉加载更多") {
return;
}
// 修改状态
this.guanzhu.loadtext = "加载中...";
// 获取数据
setTimeout(() => {
//获取完成
let obj = {
userpic: "../../static/demo/userpic/12.jpg",
username: "哈哈",
sex: 0, //0 男 1 女
age: 25,
isguanzhu: false,
title: "我是标题",
titlepic: "../../static/demo/datapic/13.jpg",
video: false,
share: false,
path: "深圳 龙岗",
sharenum: 20,
commentnum: 30,
goodnum: 20
};
this.guanzhu.list.push(obj);
this.guanzhu.loadtext = "上拉加载更多";
}, 1000);
// this.guanzhu.loadtext="没有更多数据了";
}
当前选中的tab的索引的数据
// 上拉加载
loadmore() {
if (this.tablist[this.tabIndex].loadtext != "上拉加载更多") {
return;
}
// 修改状态
this.tablist[this.tabIndex].loadtext = "加载中...";
// 获取数据
setTimeout(() => {
//获取完成
let obj = {
userpic: "../../static/demo/userpic/12.jpg",
username: "哈哈",
sex: 0, //0 男 1 女
age: 25,
isguanzhu: false,
title: "我是标题",
titlepic: "../../static/demo/datapic/13.jpg",
video: false,
share: false,
path: "深圳 龙岗",
sharenum: 20,
commentnum: 30,
goodnum: 20
};
this.tablist[this.tabIndex].list.push(obj);
this.tablist[this.tabIndex].loadtext = "上拉加载更多";
}, 1000);
}
调用方法
onReachBottom() {
this.loadmore();
},
本节代码
topic-detail.vue页面
<template>
<view>
<!-- 话题介绍 -->
<topic-info :item="topicInfo"></topic-info>
<!-- tabbar切换 -->
<swiper-tab-head :tabBars="tabBars" :tabIndex="tabIndex" @tabtap="tabtap" scrollStyle="border-bottom:0;"
scrollItemStyle="width:50%;">
</swiper-tab-head>
<view class="topic-detail-list" :style="{height: swiperheight+'px'}">
<block v-for="(item,index) in tablist" :key="index">
<template v-if="tabIndex==index">
<block v-for="(list,listindex) in item.list" :key="listindex">
<common-list :item="list" :index="listindex"></common-list>
</block>
<!-- 上拉加载 -->
<load-more :loadtext="item.loadtext"></load-more>
</template>
</block>
</view>
</view>
</template>
<script>
import topicInfo from '@/components/topic/topic-info.vue';
import swiperTabHead from '@/components/index/swiper-tab-head.vue';
import commonList from '@/components/common/common-list.vue';
import loadMore from '@/components/common/load-more.vue';
export default {
components: {
topicInfo,
swiperTabHead,
commonList,
commonList,
loadMore
},
data() {
return {
swiperheight: 500,
srcollTopValue: 0, // 默认是0
topicInfo: {
titlepic: "../../static/demo/topicpic/13.jpeg",
title: "忆往事,敬余生",
desc: "我是描述",
totalnum: 1000,
todaynum: 1000,
},
tabIndex: 0,
tabBars: [{
name: "默认",
id: "moren"
},
{
name: "最新",
id: "zuixin"
},
],
tablist: [{
loadtext: "上拉加载更多",
list: [
// 文字
{
userpic: "../../static/demo/userpic/12.jpg",
username: "哈哈",
sex: 0, //0 男 1 女
age: 25,
isguanzhu: false,
title: "我是标题",
titlepic: "",
video: false,
share: false,
path: "深圳 龙岗",
sharenum: 20,
commentnum: 30,
goodnum: 20
},
// 图文
{
userpic: "../../static/demo/userpic/12.jpg",
username: "哈哈",
sex: 0, //0 男 1 女
age: 25,
isguanzhu: false,
title: "我是标题",
titlepic: "../../static/demo/datapic/13.jpg",
video: false,
share: false,
path: "深圳 龙岗",
sharenum: 20,
commentnum: 30,
goodnum: 20
},
// 视频
{
userpic: "../../static/demo/userpic/12.jpg",
username: "哈哈",
sex: 0, //0 男 1 女
age: 25,
isguanzhu: false,
title: "我是标题",
titlepic: "../../static/demo/datapic/13.jpg",
video: {
looknum: "20w",
long: "2:47"
},
share: false,
path: "深圳 龙岗",
sharenum: 20,
commentnum: 30,
goodnum: 20
},
]
},
{
loadtext: "上拉加载更多",
list: [
// 文字
{
userpic: "../../static/demo/userpic/12.jpg",
username: "哈哈",
sex: 0, //0 男 1 女
age: 25,
isguanzhu: false,
title: "我是标题",
titlepic: "",
video: false,
share: false,
path: "深圳 龙岗",
sharenum: 20,
commentnum: 30,
goodnum: 20
},
// 图文
{
userpic: "../../static/demo/userpic/12.jpg",
username: "哈哈",
sex: 0, //0 男 1 女
age: 25,
isguanzhu: false,
title: "我是标题",
titlepic: "../../static/demo/datapic/13.jpg",
video: false,
share: false,
path: "深圳 龙岗",
sharenum: 20,
commentnum: 30,
goodnum: 20
},
// 视频
{
userpic: "../../static/demo/userpic/12.jpg",
username: "哈哈",
sex: 0, //0 男 1 女
age: 25,
isguanzhu: false,
title: "我是标题",
titlepic: "../../static/demo/datapic/13.jpg",
video: {
looknum: "20w",
long: "2:47"
},
share: false,
path: "深圳 龙岗",
sharenum: 20,
commentnum: 30,
goodnum: 20
},
]
},
]
}
},
onLoad() {
uni.getSystemInfo({
success: (res) => {
console.log('当前window高度和窗口高度');
console.log(res.windowHeight);
console.log(res.screenHeight);
let height = res.windowHeight - uni.upx2px(100)
this.swiperheight = height;
}
});
},
onReachBottom() {
this.loadmore();
},
methods: {
// tabbar点击事件
tabtap(index) {
// console.log(index);
this.tabIndex = index;
},
// 上拉加载
loadmore() {
if (this.tablist[this.tabIndex].loadtext != "上拉加载更多") {
return;
}
// 修改状态
this.tablist[this.tabIndex].loadtext = "加载中...";
// 获取数据
setTimeout(() => {
//获取完成
let obj = {
userpic: "../../static/demo/userpic/12.jpg",
username: "哈哈",
sex: 0, //0 男 1 女
age: 25,
isguanzhu: false,
title: "我是标题",
titlepic: "../../static/demo/datapic/13.jpg",
video: false,
share: false,
path: "深圳 龙岗",
sharenum: 20,
commentnum: 30,
goodnum: 20
};
this.tablist[this.tabIndex].list.push(obj);
this.tablist[this.tabIndex].loadtext = "上拉加载更多";
}, 1000);
}
}
}
</script>
<style>
</style>