1

I do a request to a service and fill an object that have multiple arrays inside and it's an array itself. ex: this.Jprojs: [{name : 'test', ListItem1 : [], ListItem2 : [] }]

I put that object in a v-for:

<div id="app">
<table class="table table-striped">
  <tr>
    <th width="15%">Proj</th>
    <th>Detail</th>
  </tr>
  <tr v-for="proj in Jprojs" :key="proj.name">
    <td style="vertical-align:middle;"><strong>{{proj.name}}</strong><br/><a v-on:click="list(proj)"> <font-awesome-icon icon="tasks" /></a></td>
    <td>{{proj.ListItem1.length}}</td>
  </tr>
</table>

I have the method list:

list : function(proj){
    axios.get(url).then(
      response => {
        this.$set(proj.ListItem1,0,response.data.value);
        //Vue.set(proj.ListItem1,0,response.data.value);
        this.nextTick;
        console.log(proj)
      },
      error => {
      },
      err => { }
    );
}

The console shows the update but the html is not updated.

2 Answers 2

1

Make sure to update the Jprojs value, instead of proj. You coud pass an index instead of the proj object.

Get the index with v-for="(proj, index) in Jprojs" and pass it as list(index). Then just edit the Jprojs array with the given index; Jprojs[index].ListItem1 = ...

Sign up to request clarification or add additional context in comments.

Comments

0

I found the problem, Actually the property ListItem1 was not in the original Json so vue was not recognizing. what I did was use vue.$set correctly, was using Wrong

both work

this.$set(proj,"ListItem1",response.data.value);
Vue.set(proj,"ListItem1",response.data.value);

Comments

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.