Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
Why nested array dynamic update is not working in my case

Hi i have a problem with nested array dynamic update as shown in below image

enter image description here

Here is a steps to re-produce the problem

  1. click on Add Likes button it will add likes for eg New Apple
  2. my default like is Mango
  3. click on Add about button it will add next row (Mango is not appeared) click on Add Likes to see the problem.

For reducing code readability i have put helper function into a mixin file called mixin.js

Expectation: i can add any number of Add about and Add Likes(with default value Mango)

Here is my code: https://codesandbox.io/s/musing-hawking-di4d3?file=/src/App.vue

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

First, you don't need a nested array for the tags property. Use:

getLikesTemplate() {
  let year = this.year;
  let template = {
    id: this.getUniqueId(),
    like: `I'm ${year} Old and like things like`,
    tags: [this.getTagsTemplate("Mango")]          //nesting removed
  };
  this.year++;
  return template;
}

Secondly, in JS objects are passed by reference, so you can do this:

method:

addLikes(like) {                                   //removed the extra code
  like.tags.push(this.getTagsTemplate("New Apple"));
},

template:

... 
<div style="text-align: left; display: flex">
  <div>                               //nesting removed
    <div class="tags" v-for="tag in like.tags" :key="tag.id">    
      {{ tag.name }}
    </div>
  </div>                              //passing the reference to the object
  <button style="margin-left: 20px" @click="addLikes(like)">
    Add Likes
  </button>
</div>

Result img

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!