我收到下拉菜单的“无法读取未定义的属性'办公室'”错误

时间:2019-11-25 16:20:01

标签: javascript vue.js

据我所知,一切均已正确设置,但仍会引发此错误。我知道数据已经存在,因为我在之前的迭代中已经完成了相同的设置,并且效果很好。有什么我想念的吗?

还是我会以错误的方式进行操作?

    <div class="col-12">
      <div class="form-group">
        <label>Escrow Office</label>
        <v-select
            class="highlights"
            :options="select.offices"
            :on-change="selectOffice"
            :searchable="false"
            :clear-search-on-select="false"
            v-model="select.officeSelected"
        ></v-select>
      </div>
    </div>
data() {
  return {
    now: new Date().toISOString(),
    document: {
      escrow_office_id: 1,
    }
  }
},
methods: {
  init(){
    if(this.listing != null) {
            getEscrow() {
               this.page.loading = true;
               axios.get('/api/v2/escrows/' + this.page.id, {headers: {'Authorization': 
               'Bearer ' + this.$root.access_token}})
            .then(response => {
               this.escrow = response.data.escrow;
               this.document.escrow_office_id = response.data.escrow.escrow_office_id;
               this.select.officeSelected = this.select.offices.find(x => x.value === 
               this.form.escrow_office_id);
            })
            .catch(e => {
             var err = (!!e.response ? (!!e.response.data ? (!!e.response.data.error ? 
             e.response.data.error : '') : '') : '');
              if (err != "") this.$noty.error("Error: " + err);
              else this.$noty.error("Cannot call getEscrow()");
            })
            .finally(() => {
            this.page.loading = false;
      });
  },
  getShared() {
    this.select.offices = this.$root.shared.escrow_offices;
  },
  selectOffice(option) {
    this.select.officeSelected = option;
    this.document.escrow_office_id = option.value;
  },
},
    }
  }
}

mounted() {
  this.getShared();
  this.getEscrow();
  setTimeout(() => { this.loaded = true; }, 1000);
},

1 个答案:

答案 0 :(得分:0)

您需要从数据函数中返回select

data() {
    return {
        select: // Your select object
        now: new Date().toISOString(),
        document: {
            escrow_office_id: 1
        }
    };
}