6

我正在使用 element-ui 和 vuejs。我有一个看起来像这样的选择元素

<el-form-item label="City" prop="city">
     <el-select 
            v-model="form.city" 
            multiple 
            filterable
            remote
            auto-complete = "address-level2"
            no-match-text = "No data found"
            :remote-method = "remoteMethod"
            :loading = "loading"
            placeholder="Select City">
          <el-option
            v-for = "(item,index) in cities"
            :key = "index"
            :label = "item.name"
            :value = "item.key"
          ></el-option>
     </el-select>
</el-form-item>

现在我想在用户选择一个选项后触发此选择的模糊事件,以便下拉选项折叠。

这是我的远程方法

remoteMethod: _.throttle(function(query) {
        this.loading = true;
        axios({
            method: 'get',
            url: someUrl
        }).then(response =>{
            if(response.data.status === false){
                this.$notify.error({
                    title: 'Error',
                    message: response.data.message
                });
            }
            else if(response.data.status === true && response.data.data.length != 0){
                this.loading = false;
                this.cities = response.data.data;
            }
        })            
    }, 1500),
4

2 回答 2

4

您可以像 ref="select1" 一样在组件上设置 ref 属性

然后你可以通过 this.$refs 调用 focus 或 blur 方法

就像:this.$refs.select1.focus()

http://element.eleme.io/#/en-US/component/select

于 2018-05-03T02:11:50.163 回答
-2

如果您想在用户选择一个选项后隐藏下拉选项,只需重置 data get from remote on event change

例子:

resetData()选择值改变时调用方法:

<el-form-item label="City" prop="city">
    <el-select 
      @change="resetData"
      v-model="form.city" 
      multiple 
      filterable
      remote
      auto-complete = "address-level2"
      no-match-text = "No data found"
      :remote-method = "remoteMethod"
      :loading = "loading"
      placeholder="Select City">
        <el-option
            v-for = "(item,index) in cities"
            :key = "index"
            :label = "item.name"
            :value = "item.key">
        </el-option>
    </el-select>
</el-form-item>

重置从远程获取的数据:

resetData() {
    this.cities = [];
},
于 2018-06-18T07:58:39.243 回答