Skip to content
This repository has been archived by the owner on Mar 1, 2021. It is now read-only.

Commit

Permalink
add infinite scroll support
Browse files Browse the repository at this point in the history
  • Loading branch information
jwenjian committed Aug 12, 2020
1 parent c342130 commit 86d685d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"sass-loader": "^9.0.3",
"sass-resources-loader": "^2.0.3",
"schema-utils": "^2.7.0",
"vue": "^2.6.11"
"vue": "^2.6.11",
"vue-infinite-scroll": "^2.0.2"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.4.0",
Expand Down
15 changes: 13 additions & 2 deletions src/components/Timeline.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="hello">
<div v-infinite-scroll="loadNextPage" infinite-scroll-disabled="busy" infinite-scroll-distance="10">
<ul class="timeline">
<li class="year first">2020</li>
<li class="event" v-for="e in events" :key="e.id">
Expand All @@ -9,6 +9,9 @@
</span>
<div class="md-result" v-html="e.htmlContent"></div>
</li>
<li class="event" v-show="allLoaded">
- End -
</li>
</ul>
</div>
</template>
Expand All @@ -24,14 +27,19 @@ export default {
return {
events: [],
currentPage: 0,
maxPage: 0,
busy: false,
allLoaded: false
};
},
methods: {
mdRender(mdStr) {
return md.render(mdStr);
},
loadNextPage() {
if (this.allLoaded) {
return;
}
this.busy = true;
axios.default
.create()
.get(`/data/data-${this.currentPage}.json`)
Expand All @@ -49,13 +57,16 @@ export default {
}${d.getHours()}:${d.getMinutes()}`;
});
this.currentPage = this.currentPage + 1;
this.busy = false;
})
.catch((err) => {
if (err.response.status === 404) {
this.allLoaded = true;
console.log("no more data");
} else {
console.log("fail");
}
this.busy = false;
});
},
},
Expand Down
2 changes: 2 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Vue from 'vue'
import App from './App.vue'
import 'normalize.css'
const infiniteScroll = require('vue-infinite-scroll');
Vue.use(infiniteScroll)

Vue.config.productionTip = false

Expand Down

0 comments on commit 86d685d

Please sign in to comment.