vue 加载更多
<template> <div> <ul> <li v-for="item in articles"> <h2>{{item.title}}</h2> <img :src="item.images" alt=""> </li> </ul> </div></template><script> import axios from 'axios'; export default{ data(){ return { articles : [] } }, mounted(){ // 缓存指针 let _this = this; // 设置一个开关来避免重负请求数据 let sw = true; // 此处使用node做了代理 .then(function(response){ // console.log(JSON.parse(response.data).stories); // 将得到的数据放到vue中的data _this.articles = JSON.parse(response.data).stories; }) .catch(function(error){ console.log(error); }); // 注册scroll事件并监听 window.addEventListener('scroll',function(){ // console.log(document.documentElement.clientHeight+'-----------'+window.innerHeight); // 可视区域高度 // console.log(document.body.scrollTop); // 滚动高度 // console.log(document.body.offsetHeight); // 文档高度 // 判断是否滚动到底部 if(document.body.scrollTop + window.innerHeight >= document.body.offsetHeight) { // console.log(sw); // 如果开关打开则加载数据 if(sw==true){ // 将开关关闭 sw = false; .then(function(response){ console.log(JSON.parse(response.data)); // 将新获取的数据push到vue中的data,就会反应到视图中了 JSON.parse(response.data).stories.forEach(function(val,index){ _this.articles.push(val); // console.log(val); }); // 数据更新完毕,将开关打开 sw = true; }) .catch(function(error){ console.log(error); }); } } }); } }</script><style lang="less"> *{ margin:0; padding:0; } li{ list-style:none; }</style> |
vue 加载更多的更多相关文章
- vue 加载更多2
<template lang="html"> <div class="yo-scroll" :class="{'down':(sta ...
- vue2.0 自定义 下拉刷新和上拉加载更多(Scroller) 组件
1.下拉刷新和上拉加载更多组件 Scroller.vue <!-- 下拉刷新 上拉加载更多 组件 --> <template> <div :style="mar ...
- 基于 Vue.js 的移动端组件库mint-ui实现无限滚动加载更多
通过多次爬坑,发现了这些监听滚动来加载更多的组件的共同点, 因为这些加载更多的方法是绑定在需要加载更多的内容的元素上的, 所以是进入页面则直接触发一次,当监听到滚动事件之后,继续加载更多, 所以对于无 ...
- 【Vue.js】加载更多—vue-infinite-scroll
引言 今天用到了一个加载更多的插件,用起来很方便,插件的名字叫做vue-infinite-scroll 我们可以去npmjs.com官网看一下这个vue-infinite-scroll的用法,官网上面 ...
- 【转载】Vue自定义指令实现pc端加载更多
转载来源:https://www.86886.wang/detail/5a6f19e644f9da55274c3bbd,谢谢作者分享! 原理 document.documentElement.scro ...
- 使用vue之directive设计列表加载更多
背景 之前写过一篇<纯JS实现加载更多(VUE框架)>,它的逻辑思路比较清晰易懂,而今天看了一天公司项目的部分功能代码,发现同事们写的加载更多的功能更加的有趣,而且易于封装到一个组件当中, ...
- Vue——轻松实现vue底部点击加载更多
前言 需求总是不断改变的,好吧,今天就把vue如何实现逐步加载更多和分布加载更多说下,默认你知道如何去请求数据的哈 一次请求 页面 使用slice来进行限制展现从0,a的数据 <div v-fo ...
- vue+better-scroll 下拉刷新,上拉加载更多
better-scroll 来做下拉刷新和 上拉加载 特别方便. 安装好vue脚手架和better-scroll 之后 直接复制粘贴就可以看到效果了 <template> <div ...
- vue移动端上拉加载更多
LoadMore.vue <template> <div class="load-more-wrapper" @touchstart="touchSta ...
随机推荐
- 【CART与GBDT】
一.CART(分类回归树) 1.思想: 一种采用基尼信息增益作为划分属性的二叉决策树.基尼指数越小,表示纯度越高. 2.回归: 每个节点都有一个预测值,预测值等于属于该节点的所有样例的 ...
- ASP.NET学习笔记(1)
1.ASP.Net简介 A.ASP.Net动态网页技术.在服务器端运行.Net代码,动态生成HTML.在浏览器可以使用JavaScript.Dom完成前台工作.如存储数据.访问数据库.业务逻辑运算等可 ...
- web页面判断是否首次加载
判断web页面是否是首次加载: if(!window.name){ window.name ='name' this.setState({ note:true })}
- [js] Array.slice和类数组转数组
a.call(b) 相当于把a方法放到b的原型上(实例私有方法)执行 Array.slice的用途 https://juejin.im/post/5b20b8596fb9a01e8d6a47c0 用法 ...
- (转)spring计划任务,springMvc计划任务,Spring@Scheduled,spring定时任务
一.计划任务实现类 1.用@Component注解标识计划任务类,这样spring可以自动扫描 2.在方法中使用注解标识要执行的方法:@Scheduled(cron="*/30 * * * ...
- tf.nn.embedding_lookup函数【转载】
转自:https://www.cnblogs.com/gaofighting/p/9625868.html //里边有两个很好理解的例子. tf.nn.embedding_lookup(params, ...
- [LeetCode] 111. Minimum Depth of Binary Tree_Easy tag:DFS
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- flow ci的构建
自动构建遇到的问题. 1. Analyzing dependencies Pre-downloading: `WeiboSDK` from `https://github.com/sinaweibos ...
- Redis:redis.conf配置
redis.conf配置: 配置主要分为几类:基础.快照.复制.安全.限制.详细日志.虚拟内存.高级配置.文件包含 ##------------------------------------基础配置 ...
- vue滚动事件销毁,填坑
eg:富文本的头部固定,当滚轮大于200时(举例)固定在浏览器头部,距离大于富文本时,头部消失 效果: 在富文本下面加一个空div 这么写: mounted() { $(window).scroll( ...