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);
  }
}       

这里的场所列表 id 仅在我刷新页面后才会更新。即使数据是之前到达的(正如我所做的那样 console.log(this.venues) 检查数据是否到达)

4

1 回答 1

0

文档中所述,数组元素的直接分配不是反应式的。

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

相反,你可以做

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

请注意,您的原始代码也缺少第二个参数中的索引Object.assign

于 2018-05-30T21:47:46.763 回答