Skip to content
This repository has been archived by the owner on Nov 15, 2018. It is now read-only.

Commit

Permalink
fix: (#450) 修复动态详情返回列表时滚动状态丢失的问题
Browse files Browse the repository at this point in the history
hack router scroll behavior
  • Loading branch information
mutoe committed Jul 4, 2018
1 parent 88b2e32 commit e272172
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/page/feed/FeedList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,16 @@ export default {
}
},
watch: {
feedType(val) {
feedTypesMap.includes(val) && this.$refs.loadmore.beforeRefresh();
feedType(val, oldVal) {
feedTypesMap.includes(val) &&
oldVal &&
this.$refs.loadmore.beforeRefresh();
}
},
created() {
this.onRefresh(() => {});
},
methods: {
onRefresh(callback) {
api.getFeedsByType(this.feedType, 15).then(({ data }) => {
Expand Down
9 changes: 7 additions & 2 deletions src/routers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ const router = new VueRouter({
};
}
if (savedPosition) {
return savedPosition;
// hack 滚动到保存的位置, 原生方法失效的问题
setTimeout(() => {
window.scrollTo(savedPosition.x, savedPosition.y);
}, 100);
} else {
const {
meta: { keepAlive = false, toTop = false }
Expand All @@ -26,7 +29,9 @@ const router = new VueRouter({
from.meta.savedPosition =
document.body.scrollTop || document.documentElement.scrollTop;
}
return { x: 0, y: to.meta.savedPosition || 0 };
setTimeout(() => {
window.scrollTo(0, to.meta.savedPosition);
}, 100);
}
}
});
Expand Down

0 comments on commit e272172

Please sign in to comment.