How to load data by sliding in vue mobile UI framework
This article mainly introduces the sliding loading method of vue mobile UI framework. Now I will share it with you and give you a reference.
Preface
There is also a very commonly used component on our mobile terminal, which is sliding to load more components. Usually we see many plug-ins that are quite complicated to implement and think that this component is difficult, but it is not! ! This component can actually be implemented very easily, and the experience can be very great (of course we did not implement the pull-down refresh function)! ! Let's implement this component together.
Effect display
First, a gif picture shows the effect after we make it, as follows:
DOM structure
The page should contain three parts: 1. Text area 2. Load the chrysanthemum and record text 3. Load all data Completed text:
<p ref="scroll" class="r-scroll"> <p class="r-scroll-wrap"> <slot></slot> </p> <slot name="loading"> <p v-show="isLoading" class="r-scroll-loading"> <r-loading></r-loading> <span class="r-scroll-loading-text">{{loadingText}}</span> </p> </slot> <slot name="complate"> <p v-show="isComplate" class="r-scroll-loading">{{complateText}}</p> </slot> </p>
css style
The container r-scroll of the entire component should be The width is fixed, and the excess part can be scrolled; the text area should automatically grow with the content and height; the loading chrysanthemum is displayed when the scroll distance is the default value at the bottom; after all data is loaded, the data loading completion text is displayed:
<style lang="scss"> @mixin one-screen { position: absolute; left:0; top:0; width:100%; height:100%; overflow: hidden; } @mixin overflow-scroll { overflow: scroll; -webkit-overflow-scrolling: touch; } .r-scroll{ @include one-screen; @include overflow-scroll; &-loading{ text-align: center; padding-top: 3vw; padding-bottom: 3vw; font-size: 14px; color: #656565; line-height: 20px; &-text{ display: inline-block; vertical-align: middle; } } } </style>
javascript
Interaction logic analysis:
Page initialization At this time, obtain the entire component node and the text container node
Bind the scroll event to the entire container node
Judge during the scrolling process of the container Whether the distance from the top is less than the specified value, if it is less than the custom event loadmore
Listen to the loadmore event in the business code, and if it is triggered, load the data
Because the code is not complicated, I will not analyze it in detail. Please read the code comments. If you are unclear, please leave a comment in the comments:
<script> import rLoading from '../loading' export default{ components: {rLoading}, props: { // 距离底部数值,小于或等于该数值触发自定义事件loadmore bottomDistance: { type: [Number, String], default: 70 }, // 加载中的文字 loadingText: { type: String, default: '加载中...' }, // 数据加载完成的文字 complateText: { type: String, default: '-- 我是个有底线的列表 --' } }, data () { return { // 用来判定数据是否加载完成 isComplate: false, // 用来判定是否正在加载数据 isLoading: false, // 组件容器 scroll: null, // 正文容器 scrollWrap: null } }, watch: { // 监听isLoading,如果isLoading的值为true则代表触发了loadmore事件 isLoading (val) { if (val) { this.$emit('loadmore') } } }, methods: { // 初始化组件,获取组件容器、正文容器节点,并给组件容器节点绑定滚动事件 init () { this.scroll = this.$refs.scroll this.scrollWrap = this.scroll.childNodes[0] this.scroll.addEventListener('scroll', this.scrollEvent) this.$emit('init', this.scroll) }, scrollEvent (e) { // 如果数据全部加载完成了,则再也不触发loadmore事件 if (this.isComplate) return let scrollTop = this.scroll.scrollTop let scrollH = this.scroll.offsetHeight let scrollWrapH = this.scrollWrap.offsetHeight // 组件容器滚的距离 + 组件容器本身距离大于或者等于正文容器高度 - 指定数值 则触发loadmore事件 if (scrollTop + scrollH >= scrollWrapH - this.bottomDistance) { this.isLoading = true } }, // 当前数据加载完成后调用该函数 loaded () { this.isLoading = false }, // 所有数据加载完成后调用该函数 compleate () { this.isLoading = false this.isComplate = true this.scroll.removeEventListener('scroll', this.scrollEvent) } }, mounted () { this.$nextTick(this.init) } } </script>
In addition, this The loading chrysanthemum component is referenced in the component, and a small chrysanthemum component code is appended. Because the code is simple, I will not analyze it in detail:
Chrysanthemum uses a gif picture, please take a photo of your favorite chrysanthemum gif and put it in The path of the chrysanthemum component
<template> <p class="r-loading-container"> <img src="./loading.gif"> </p> </template> <script> export default {} </script> <style lang="scss"> .r-loading-container{ display: inline-block; vertical-align: middle; img{ width: 20px; height: 20px; display: block; } } </style>
is written at the end
Finally, here is an appendix of a usage example. :
<template> <p class="index"> <r-scroll ref="scroll" @loadmore="queryDate"> <p class="item" v-for="(item, index) in list">{{item}}</p> </r-scroll> </p> </template> <script> import rScroll from '../../components/scroll' function timeout (ms) { return new Promise((resolve, reject) => { setTimeout(resolve, ms, 'done') }) } export default{ components: {rScroll}, data () { return { i: 0, list: [] } }, methods: { async queryDate () { await timeout(1000) let i = this.i let data = [] for (let j = 0; j < 40; j++) { data.push(i + j) this.i = this.i + 1 } this.list = this.list.concat(data) // 调用组件中的loaded函数,如果数据加载完成后记得调用组件的compleate函数 this.$refs.scroll.loaded() } }, mounted () { this.queryDate() } } </script> <style lang="scss"> .item{ background-color: #f2f2f2; border-bottom: 1px solid #fff; height: 40px; line-height: 40px; text-align: center; } </style>
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Using vue2 to implement shopping cart and address selection functions
Angular development practice server-side rendering
vue Sample code to implement select all and none
The above is the detailed content of How to load data by sliding in vue mobile UI framework. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



DDREASE is a tool for recovering data from file or block devices such as hard drives, SSDs, RAM disks, CDs, DVDs and USB storage devices. It copies data from one block device to another, leaving corrupted data blocks behind and moving only good data blocks. ddreasue is a powerful recovery tool that is fully automated as it does not require any interference during recovery operations. Additionally, thanks to the ddasue map file, it can be stopped and resumed at any time. Other key features of DDREASE are as follows: It does not overwrite recovered data but fills the gaps in case of iterative recovery. However, it can be truncated if the tool is instructed to do so explicitly. Recover data from multiple files or blocks to a single

0.What does this article do? We propose DepthFM: a versatile and fast state-of-the-art generative monocular depth estimation model. In addition to traditional depth estimation tasks, DepthFM also demonstrates state-of-the-art capabilities in downstream tasks such as depth inpainting. DepthFM is efficient and can synthesize depth maps within a few inference steps. Let’s read about this work together ~ 1. Paper information title: DepthFM: FastMonocularDepthEstimationwithFlowMatching Author: MingGui, JohannesS.Fischer, UlrichPrestel, PingchuanMa, Dmytr

If you need to know how to use filtering with multiple criteria in Excel, the following tutorial will guide you through the steps to ensure you can filter and sort your data effectively. Excel's filtering function is very powerful and can help you extract the information you need from large amounts of data. This function can filter data according to the conditions you set and display only the parts that meet the conditions, making data management more efficient. By using the filter function, you can quickly find target data, saving time in finding and organizing data. This function can not only be applied to simple data lists, but can also be filtered based on multiple conditions to help you locate the information you need more accurately. Overall, Excel’s filtering function is a very practical
![Error loading plugin in Illustrator [Fixed]](https://img.php.cn/upload/article/000/465/014/170831522770626.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
When launching Adobe Illustrator, does a message about an error loading the plug-in pop up? Some Illustrator users have encountered this error when opening the application. The message is followed by a list of problematic plugins. This error message indicates that there is a problem with the installed plug-in, but it may also be caused by other reasons such as a damaged Visual C++ DLL file or a damaged preference file. If you encounter this error, we will guide you in this article to fix the problem, so continue reading below. Error loading plug-in in Illustrator If you receive an "Error loading plug-in" error message when trying to launch Adobe Illustrator, you can use the following: As an administrator

The performance of JAX, promoted by Google, has surpassed that of Pytorch and TensorFlow in recent benchmark tests, ranking first in 7 indicators. And the test was not done on the TPU with the best JAX performance. Although among developers, Pytorch is still more popular than Tensorflow. But in the future, perhaps more large models will be trained and run based on the JAX platform. Models Recently, the Keras team benchmarked three backends (TensorFlow, JAX, PyTorch) with the native PyTorch implementation and Keras2 with TensorFlow. First, they select a set of mainstream

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile
