1

I want to access topicCategories in child component. I've tried $this.$parent.$parent.topicCategories but it is undefined, even though i can see it in console?

So i tried the below method but this only shows topicCategories of the previous page not the current page. So first time you view a post, it is empty, then the next post, you see the topicCategories of the previous post.

parent (post.vue)

   this.topicCategories = this.Categories.map((category: any) => category.id);
    this.$store.dispatch('app/setCurrentCategories', topicCategories);

child component (read.vue)

if(this.$store.state.app.currentCategories.length) {

        const categories = this.$store.state.app.currentCategories.map((category: any) => category.id);
      
        }

How do i get topicCategories in the child component of the current page?

user892134
  • 3,078
  • 16
  • 62
  • 128
  • 2
    The use of $parent is an antipattern. If you need something in a child, pass it through a prop. "but it is undefined, even though i can see it in console" - there's race condition, it's this problem https://stackoverflow.com/questions/17546953/cant-access-object-property-even-though-it-shows-up-in-a-console-log?rq=1 – Estus Flask Aug 06 '22 at 16:45

0 Answers0