Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dealing with nested/complex objects in vuex

Is there someone familiar with Vuex and Vue.js that could help me with some code?

Either by handing me advice, or point me towards some similar situation to solve my problem.

I have a comment section (module: comments) representing an array of comment object. Each comment have a 'tags section', 'replies section', needing to be reactive on mutations and to store mutations in db.

  • Option 1: having only one module: comments containing actions for all entities (comments, tags, replies) - would fill comments module with unrepresentative actions
  • Option 2: having 'replies, tags' and asociated actions living as vue data of components 'replies section' and 'tags section'
  • Option 3: described here https://forum.vuejs.org/t/vuex-best-practices-for-complex-objects/10143/2 , but I don't know if I need to have a module for each entity (comments, replies, tags)

with mention of that my API returns nested object:

`comments:[
  {
    id,
    title,
    text,
    replies: [{
      id,
      author: {id, name}
      comment_id,
      text
    }],
    tags: [similar with replies]
  },
//
]`
like image 471
Botea Florin Avatar asked Dec 07 '25 04:12

Botea Florin


1 Answers

If you have a lot of relational/nested data, I'd suggest trying vuex-orm. It allows you to normalize your data schema within Vuex Store with relationships, as you would represent it in regular DB. It also has a lot of integrations with axios, GraphQL, etc.

like image 128
Dima Kuzmich Avatar answered Dec 08 '25 18:12

Dima Kuzmich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!