Vue uses a mouse scroll to load data.

to scroll with the mouse on a location we went to load data, such scenes with business needs now more and more common, and now to a solution strategy in the author’s “vue.js combat” under analysis:

[ .

1 sets a flag used to determine whether the data loaded in the

2 set to the scroll area overfow:. auto (scroll display)

3 was added to monitor the scrolling region. event and bind ref property to get the DOM instance

4. when the mouse to scroll in the end section, load the data

4.1 If at this time the flag is true then exit, this time without data load

the key code is as follows:

   // this code // div ... to be abbreviated as scrolling region 
// ...
export default {data () {return {recommendList: [], // store the data to be displayed in the scroll area isLoading: false // default data is not loaded }}, methods: {// Get data getRecommendList () {// data representing loading this.isLoading = true; $ .ajax.get ( 'news / before /' + preDay) .then (res => {this. recommendList.push (res); // data request completion this.isLoading = false;})}, handleScroll () {const $ list = this $ re.FS.List; // If the data is in the load, the request exits if the request exits if (this.isloading) return; // The height of the spherped plus pages is equal to the entire content area height, it is considered to contact the bottom // scrolltop Get the rolling distance // clientHeight indicates the height of the page viewport height // scrollHeight page content ($ list.Scrolltop + Document.body.clientHeight> = $ list.ScrollHeight) {this.getRecommendList ();}}} , MOUNTED () {this.getRecommendlist ()}} Width: 300px; Position: fixed; Top: 0; Left: 150px; // Scroll Bar Overflow: Auto;
The above example of using the mouse scroll loaded data is the total content of Xiaobian sharing to everyone. I hope I can give you a reference, I also hope that everyone will support Tumi Cloud.

© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment