In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to load waterfall flow infinitely by Vue". In daily operation, I believe many people have doubts about how to load waterfall flow infinitely by Vue. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt that "Vue how to achieve infinite load waterfall flow"! Next, please follow the editor to study!
The details are as follows
The waterfall I made is banished in a nested page, which is similar to the main content in the management background. It is also convenient to change to full screen, which is actually easier because it avoids some pits that use onScroll on elements.
Through this waterfall flow, you can master the following knowledge points:
1. Listening to scroll events on elements is a little more troublesome than listening directly on window.
2. Image.onload event
3 、 promiseAll
4. Transition-group of vue
Here, mockjs is used to simulate the image data, and then the picture data is called through axios, or other data sources can be used.
Determine which column to load the picture into by calculating the height of the picture.
If there is still room on the screen, continue to load.
Infinite scrolling loading.
The screen resize is not done, it can be added later.
Directly paste the code, if you have any questions, you are welcome to discuss.
Import {getList} from "@ / api/demo" Export default {name: "Waterfall", data () {return {waterfallList: [], waterfallCol: 5, colWidth: 236, marginRight: 10, marginBottom: 10, colHeights: [], listQuery: {page: 1, limit: 5, sort: "+ id"}, loading: false, show: true} }, mounted () {this.init ();}, methods: {init () {/ / initialization, each column height is 0 this.colHeights = new Array (this.waterfallCol); for (let I = 0; I)
< this.colHeights.length; i++) { this.colHeights[i] = 0; } this.colWidth = (this.$refs.waterfall.clientWidth - (this.waterfallCol - 1) * this.marginRight) / this.waterfallCol; this.loadImgs(); }, loadImgs() { this.loading = true; // 从api获取数据 getList(this.listQuery).then(res =>{let images = res.data.items; let promiseAll = [], imgs = [], total = images.length; for (let I = 0; I
< total; i++) { promiseAll[i] = new Promise(resolve =>{imgs [I] = new Image (); imgData.width [I] .src = images [I] .image _ uri; imgs.onload = () > {let imgData = {}; imgData.height = (imgs.height * this.colWidth) / imgs.width; imgData.width = this.colWidth ImgData.src = images [I]. Image _ uri; this.waterfallList.push (imgData); this.rankImgs (imgData); resolve (IMGS [I]);} Promise.all (promiseAll). Then (() = > {this.loading = false; this.loadMore ();}) });}, loadMore () {if (this.$refs.waterfall.clientHeight + this.$refs.waterfall.scrollTop > this.filterMin (). MinHeight & & this.loading = = false) {this.loading = true; setTimeout (() = > {this.loadImgs ();}, 200) }, rankImgs (imgData) {let min = this.filterMin (); imgData.top = min.minHeight; imgData.left = min.minIndex * (this.colWidth + this.marginRight); this.colHeights [min.minIndex] + = imgData.height + this.marginBottom;}, filterMin () {let minHeight = Math.min.apply (null, this.colHeights) Return {minHeight: minHeight, minIndex: this.colHeights.indexOf (minHeight)};}, onScroll () {this.loadMore ();}; ul li {list-style: none;}. Wf-wrap {position: relative; width: 100%; height: 100%; overflow: scroll;}. Wf-item {position: absolute;}. Wf-item img {width: 100%; height: 100% } .list-enter-active,.list-leave-active {transition: all 1s;} .list-enter, .list-leave-to/* .list-leave-active for below version 2.1.8 * / {opacity: 0; transform: translateY (30px);} at this point, the study on "how Vue implements infinite waterfall flow" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.