0
<v-layout row wrap>
  <v-flex class="hidden-sm-and-down" md4>
    <v-subheader class="fields">Select Venue</v-subheader>
  </v-flex>
  <v-flex xs12 md8>
    <v-select class="select__box" :items="venues" v-model="venue" item-text="name" item-value="_id" label="Select Venue" prepend-icon="edit_location" autocomplete :error-messages="venueErrors" @blur="delayTouch($v.venue,200)" @input="delayTouch($v.venue,200)"></v-select>
  </v-flex>
</v-layout>


created: async function() {
  try {
    let response = await CommonRequest.getVenues();
    let array = response.data.venues;
    let i = 0;
    for (let ven of array) {
      this.venues[i] = Object.assign({}, this.venues, {
        name: ven.name,
        _id: ven._id
      });
      i++;
    }
  } catch (error) {
    if (error) console.log(error);
  }
}       

here venues list id getting updated only after I refresh my page.Even the data is arrived before (as I did console.log(this.venues) to check whether data is arrived or not)

bmayank
  • 1
  • 1
  • 7

1 Answers1

0

As noted in the docs, direct assignment of array elements isn't reactive.

  this.venues[i] = Object.assign({}, this.venues, {
    name: ven.name,
    _id: ven._id
  });

Instead you can do

  this.$set(this.venues, i, Object.assign({}, this.venues[i], {
    name: ven.name,
    _id: ven._id
  }));

Note that your original code is also missing the index in the second parameter to Object.assign

tony19
  • 125,647
  • 18
  • 229
  • 307
Stephen Thomas
  • 13,843
  • 2
  • 32
  • 53
  • ` created: async function() { try { let response = await CommonRequest.getVenues(); let array = response.data.venues; let i = 0; for (let ven of array) { this.$set( this.venues, i, Object.assign({}, this.venues[i], { name: ven.name, _id: ven._id }) ); i++; } } catch (error) { if (error) console.log(error); } } ` still not working – bmayank May 30 '18 at 21:59
  • i have setted venues:[] in data – bmayank May 30 '18 at 22:17
  • is this the tick problem(vue async updating DOM) but if it is shouldn't it automatically update the content when update patch is called? – bmayank May 31 '18 at 08:02