鍍金池/ 問答/HTML/ 使用iview的select組件進(jìn)行遠(yuǎn)程搜索時(shí),編輯功能出了問題,不能選定默認(rèn)值

使用iview的select組件進(jìn)行遠(yuǎn)程搜索時(shí),編輯功能出了問題,不能選定默認(rèn)值。

<FormItem label="負(fù)責(zé)人:" prop="chargeUserId">

        <Select v-model="cubForm.chargeUserId" 
                filterable clearable remote :remote-method="remoteMethod2"
                :loading="loading2">
          <Option v-for="item in userList" :key="item.id" :value="item.id" :label="item.name"
                  style="width: 250px">
          </Option>
        </Select>

</FormItem>

      
  這個(gè)是遠(yuǎn)程搜索的方法    
    remoteMethod2(query) { 
    let self = this;
      if (query) {
        self.loading2 = true;
        let params = {
          name: query
        }
        this.$api.get("/user/search", {params: params}).then(function (res) {
          if (res.data.code === 200) {
            self.userList = res.data.data.list;
          } else {
            self.$Message.error('獲取數(shù)據(jù)失?。? + res.data.code);
          }
        })
        this.loading2 = false;
      }
  },
  
  初始化的時(shí)候 userList已經(jīng)push了默認(rèn)的對(duì)象,頁面也顯示了

clipboard.png
可是當(dāng)我點(diǎn)擊這個(gè)select框 再點(diǎn)擊空白處的時(shí)候,select框內(nèi)的值就不見了,而且無法再選中默認(rèn)的值(圖中即“nishuo”這個(gè)值)。
clipboard.png

clipboard.png

回答
編輯回答
墨染殤

template 中設(shè)置select控件的ref屬性

<Select v-model="cubForm.chargeUserId" 
                filterable clearable remote :remote-method="remoteMethod2"
                :loading="loading2" ref="setQuery">
          <Option v-for="item in userList" :key="item.id" :value="item.id" :label="item.name"
                  style="width: 250px">
          </Option>
        </Select>

script中調(diào)用

this.$refs.setQuery.setQuery(value) //【value】為你所需要查詢的字符串或數(shù)值
2017年1月3日 12:26