vue從入門到放棄--- 滾動載入
阿新 • • 發佈:2019-02-02
import {liveCareer}from '@/api';
export default {
data() {
return {
careers:[],
search: this.search,
jobloading: false,
//無限滾動被禁用
page: 2,
//傳遞頁數
totrue: false,
//控制停止滾動
noJob: false,
//沒有資料
showLoading: true,
//是否顯示載入中
allLoaded: false,
//載入完畢
loadGif: false
//loading圖顯示隱藏
};
},
methods: {
/* 關鍵字搜尋職位 */
clearJob() {
this .careers = [];
this.page = 1;
this.totrue = true;
this.jobloading = false;
this.loadMore();
},
/* 載入第一頁 */
async liveCareer() {
this.careers = [];
let params = {
szid: this .$route.query.SzId == "null" ? "": this.$route.query.SzId,
xzid: this.$route.query.XzId == "null" ? "": this.$route.query.XzId,
pageNum: 1,
kw: this.search ? this.search: "",
type: 2
}
let res = await liveCareer(params);
if (res.JobList.length > 0) {
this.careers = res.JobList;
if (res.TotalRowCount <= 10) {
this.allLoaded = true;
this.noJob = false;
}
if (res.PageCount > 1) {
this.showLoading = true;
this.loadGif = true;
this.totrue = true;
}
} else {
this.showLoading = false;
this.noJob = true;
}
},
/* 載入職位 */
loadMore() {
this.jobloading = true;
let vm = this;
if (this.totrue) {
let params = {
szid: this.$route.query.SzId == "null" ? "": this.$route.query.SzId,
xzid: this.$route.query.XzId == "null" ? "": this.$route.query.XzId,
pageNum: this.page,
kw: this.search ? this.search: "",
type: 2
}
liveCareer(params).then(res =>{
var list1 = res.JobList;
var count = res.PageCount;
if (vm.careers.length == 0) {
vm.careers = list1;
} else {
if (this.page<= parseInt(count)){
var list2 = vm.careers;
vm.careers = list2.concat(list1);
} else {
this.totrue = false;
this.loadGif = false;
this.allLoaded = true;
}
}
this.page++;
setTimeout(() => {
vm.jobloading = false;
}, 1000);
});
} else {
this.jobloading = false;
}
}
},
created() {
this.liveCareer();
}
}