keep-alive influence @egjs/vue-infinitegrid
See original GitHub issueDescription
Excuse me, but I’d like to ask how to restore scroll position with keepAlive?
Steps to check or reproduce
my codes like this: router:
{
path: '/a',
name: 'a,
props: true,
meta: {
title: 'a-Page',
keepAlive: true,
},
component: () => import('@/.../a'),
},
...
export default new Router({
mode: 'history',
scrollBehavior (to, from, savedPosition) {
if (savedPosition && to.meta.keepAlive) {
return new Promise((resolve, reject) => {
setTimeout(() => {
window.scrollTo({
top: savedPosition.y,
left: 0,
});
}, 0);
});
}
},
});
app.vue
<template>
<div id="app" class="wrap">
<keep-alive max="1">
<router-view v-if="$route.meta.keepAlive"></router-view>
</keep-alive>
<router-view v-if="!$route.meta.keepAlive"></router-view>
</div>
</template>
a.vue
<template>
<masonry-infinite-grid
ref="ig"
id="masonry"
class="container"
v-bind:gap="-1"
v-on:request-append="onRequestAppend"
>
<div
class="list_item"
v-for="(item, index) in items"
:key="index"
:data-grid-groupkey="item.groupKey"
>
egjs {{ item.key }}
<a href="/b/id">
<img
width="200"
height="200"
v-bind:src="
'https://naver.github.io/egjs-infinitegrid/assets/image/' +
((item.key % 33) + 1) +
'.jpg'
"
alt="egjs"
/>
</a>
</div>
</masonry-infinite-grid>
</template>
<script>
import { MasonryInfiniteGrid } from "@egjs/vue-infinitegrid";
export default {
...
components: { MasonryInfiniteGrid, }
data() {
return {
items: [],
status: null
}
},
activated() {
// can't catch '$refs.ig'
this.$refs.ig.setStatus(this.status) // I want use old data in 'keepl-alive'
},
deactivated () {
this.status = this.$refs.ig.getStatus();
},
methods: {
getItems(nextGroupKey, count) {
const nextItems = [];
for (let i = 0; i < count; ++i) {
const nextKey = nextGroupKey * count + i;
nextItems.push({ groupKey: nextGroupKey, key: nextKey });
}
console.log('nextItems', nextItems)
return nextItems;
},
onRequestAppend(e) {
console.log('e', e)
const nextGroupKey = (e.groupKey || -1) + 1;
this.items = [...this.items, ...this.getItems(nextGroupKey, 10)]; },
}
}
<script>
But when I return page it has error like:
[Vue warn]: Error in activated hook: "TypeError: Cannot read properties of undefined (reading 'setStatus')
What should I do? Please help.🤕
In fact, the ‘items’ in v-for="(item, index) in items"
must use data which was stored in keepAlive. Because as requirement I have to use a button to fetch data of next page instead of ‘onRequestAppend’.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Build a Vue INFINITE SCROLLING Component - YouTube
If you've ever caught yourself on social media for way too long, chances are the site you were on was using an infinite...
Read more >ag-Grid (Vue): Infinite Row Model
The differences between row models can be found in our row models summary page. Infinite scrolling allows the grid to lazy-load rows from...
Read more >Untitled
Ss 65/2005, Yanni santorini, Egg drop project ideas with marshmallows, ... Roman melnyk lab, Infinite crisis batman skins, Leeuwenbergh tennis?
Read more >Untitled
... Arrow season 2 episode 9 easter eggs, Paniekhaak kopen, Kaplica pulsze, ... Erlang gen tcp keepalive, Subground, Hbv cpt code, Maxim wall...
Read more >A Quick Vue 3 Infinite Scrolling Component - LearnVue
An infinite scrolling component is when new content is loaded as the user scrolls down the page as opposed to separating it out...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@SageSanyue
Cannot read properties of undefined (reading 'setStatus')
is occur when first renderingAnd use requestAnimationFrame
@SageSanyue
Hi. We will investigate this issue.
I think I should check a few things before that.
<masonry-infinite-grid :status="status">
code.