2

I have been looking for this answer for a long time now. Finally posting it since I have a problem related to this.

Please check this below code snippet

<div>
    <template v-for="(row, index) in rows">
         <tr v-if="hasChildData(row, index)" :key="`row-${tabId}-${index}`">
              <!-- Rest of the logic -->
         </tr>
    </template>
</div>

Method

hasChildData(row, index) {
  console.log("Looping index: "+ index);
  return row.childData;
}

Lets say rows is an array and has 5 elements

data() {
    return {
      rows: [
        { test: 123 },
        { test: 345 },
        { test: 567 },
        { test: 789 },
        { test: 904 },
      ]
   };
}

Somewhere i try to update a specific row in rows array. In this case index 3

setChildData() {
    Vue.set(this.rows[3], "childData", true);
}

Why does Vue re-render the entire loop. Is there a way to only re-render specific index only 3 ? This is related to Change specific index without re-render whole array in Vuejs but didn't find the answer what i was looking for.

Output After calling setChildData():

Looping index: 0

Looping index: 1

Looping index: 2

Looping index: 3

Looping index: 4

While I Expect

Looping index: 3

2
  • stackoverflow.com/a/67603075/381282 Commented Jul 23, 2021 at 16:03
  • Move all things that you don't want to be rerendered to nested components. It rerenders current component, not specifically a loop. Commented Jul 23, 2021 at 16:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.