question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

keep-alive influence @egjs/vue-infinitegrid

See original GitHub issue

Description

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:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
daybrushcommented, Oct 28, 2021

@SageSanyue

Cannot read properties of undefined (reading 'setStatus') is occur when first rendering

if (this.$refs.ig && this.status) {
}

And use requestAnimationFrame

if (this.$refs.ig && this.status) {
    requestAnimationFrame(() => {
        this.$refs.ig.setStatus(this.status);
    });
}
2reactions
daybrushcommented, Oct 26, 2021

@SageSanyue

Hi. We will investigate this issue.

I think I should check a few things before that.

  1. Does activation occur before mounted?
  2. If keep-alive works, does mounted hook occur?
  3. If mounted occurs, it would be ok to write <masonry-infinite-grid :status="status"> code.
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found