vue底部加载更多
来源:互联网 发布:java与c 的区别 编辑:程序博客网 时间:2024/06/15 19:42
要实现的效果如下:
<template> <div class="newsList"> <div v-for="(items, index) in newsList"> <div class="date">{{showDay(index)}}</div> <div class="list" > <ul> <li class="list-item" v-for="item in items"> <span class="text">{{item.title}}</span> <img :src="attachImageUrl(item.images[0])" class="image"/> </li> </ul> </div> </div> <div class="infinite-scroll" v-show="loading"> <svg class="loader-circular" viewBox="25 25 50 50"> <circle class="loader-path" cx="50" cy="50" r="20" fill="none" stroke="rgb(53, 157, 218)" stroke-width="5"></circle> </svg> <span class="infinite-scroll-text">{{tips}}</span> </div> </div></template><script> import axios from 'axios'; export default { data () { return { newsList: [], date: [], todayDate: '', REQUIRE: true, loading: false, tips: '努力加载中...' } }, created () { // 获取今日新闻 axios.get('http://zhihuapi.herokuapp.com/api/4/news/latest') .then( (res) => { this.newsList.push(res.data['stories']) this.date.push(res.data['date']); this.todayDate = res.data['date'] }) }, mounted () { // 添加滚动事件,检测滚动到页面底部 window.addEventListener('scroll', this.scrollBottom) }, methods: { scrollBottom() { // 滚动到页面底部时,请求前一天的文章内容 if (((window.screen.height + document.body.scrollTop) > (document.body.clientHeight)) && this.REQUIRE) { // 请求的数据未加载完成时,滚动到底部不再请求前一天的数据 this.REQUIRE = false; this.loading = true; this.tips = '努力加载中...'; axios.get('http://zhihuapi.herokuapp.com/api/4/news/before/' + this.todayDate).then((res) => { this.newsList.push(res.data['stories']); this.date.push(res.data['date']); this.todayDate = res.data['date']; // 请求的数据加载完成后,再次滚动到底部时,允许请求前一天数据 this.$nextTick(() => { this.REQUIRE = true; this.loading = false; }); }).catch(() => { this.tips = '连接失败,请稍后重试'; // 请求失败时,将 REQUIRE 置为 true,滚动到底部时,再次请求 this.REQUIRE = true; }); } }, showDay (index) { if (index === 0) { return '今日新闻' } else { return this.getToday(index) } }, getToday (index) { let year = this.date[index].slice(0, 4); let month = this.date[index].slice(4, 6); let day = this.date[index].slice(6); let today = new Date(year + '/' + month + '/' + day); let week = ['日', '一', '二', '三', '四', '五', '六']; return month + '月' + day + '日' + ' 星期' + week[today.getDay()]; }, attachImageUrl (srcUrl) { if (srcUrl !== undefined) { return 'http://read.html5.qq.com/image?src=forum&q=5&r=0&imgflag=7&imageUrl=' + srcUrl.slice(0, 4) + srcUrl.slice(5); } } } }</script>
阅读全文
0 0
- vue底部加载更多
- RecycleView 添加底部加载更多
- 上拉到底部加载更多
- vue上拉加载更多
- ListView滚动到底部自动加载更多
- listview底部加载更多的操作
- ListView滚动到底部自动加载更多
- RecyclerView实现底部加载更多功能
- 页面下拉到底部自动加载更多
- js滑动到底部加载更多
- 网页下滑到底部之后加载更多
- vue中实现滚动加载更多
- vue瀑布流组件滑动加载更多
- vue.js 列表数据加载更多
- vue滚到底部加载数据
- Sencha Touch 用scroller实现滚到底部加载更多
- JS滚动条到网页底部自动加载更多内容
- scrollview 实现滑动到底部加载更多数据
- 将Bean类保存在本地,已JSON的形式提交,便于其他页面读取。常用于购物车
- String,StringBuffer与StringBuilder的区别
- 模板模式
- MySQL 数据的基本操作
- Finance系列(5)之E-Banking Systems
- vue底部加载更多
- mysql_权限
- hdu 1233 还是畅通工程
- c++Socket简单通信服务器端
- 添加沙箱技术测试者 邮件验证失败
- UVA 1646圈图的匹配
- tinyxml
- 登录界面中的验证码的使用
- POJ 1852 Ants