基于JS實現(xiàn)父組件的請求服務過程解析
更新時間:2019年10月14日 09:27:50 作者:彭勝光
這篇文章主要介紹了基于JS實現(xiàn)父組件的請求服務過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
這篇文章主要介紹了基于JS實現(xiàn)父組件的請求服務過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
<template> <div class = 'car_list' reft='scrollobx' @scroll='scrollready($event)'> </div> </template> <script> export default { data() { return { lengthThreshold: 50, //當滑動到距離低端50px時,更新數(shù)據(jù) timeThreshold: 300, promise: null } }, methods: { // 滾動加載列表 scrollready() { if(this.shouldScroll()) { if (this.promise) { return; } // 進行加載 this.fn(); // 防止多次滑動,頻繁請求后臺資源 let self = this; this.promise = setTimeout(() => { self.promise = null; }, this.timeThreshold); } }, // 調用父組件請求資源服務 fn() { this.$emit('scrollChange'); }, shouldScroll() { if(document.scrollTop === 0) {// 滑動距離為0,還沒開始滑動 return false; }<br data-filtered="filtered"> // 列表高度 - 列表可視高度 - 滑動的高度 < 50px , 則加載更多 return this.$refs.scrollbox.scrollHeight - this.$refs.scrollbox.clientHeight - this.$refs.scrollbox.scrollTop < this.lengthThreshold; }, } } </script>
父組件的請求服務方法:
queryCarApplyShareList() { this.Load = true; CarResources.methods.queryCarApplyShareList(this.http, this.pageNo, this.pageSize).then((res) => { if (res && res.status === 200) { if (this.pageNo === 1) { // 加載第一頁數(shù)據(jù) this.CarList = res.data || []; } else { // 加載更多 this.CarList = <strong>this.CarList.concat(res.data);</strong> } this.IsLastPage = res.data.length === 0 } this.Load = false; }, () => { this.Load = false; console.log('接口報錯'); }); },
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
js表單元素checked、radio被選中的幾種方法(詳解)
下面小編就為大家?guī)硪黄猨s表單元素checked、radio被選中的幾種方法(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-08-08js showModalDialog 彈出對話框的簡單實例(子窗體)
本篇文章主要是對js_showModalDialog彈出對話框的簡單實例(子窗體) 進行了詳細的介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-01-01