如何在选择选项后使用element-ui和vuejs触发“select”模糊事件?

时间:2018-05-02 09:20:52

标签: vue.js element-ui

我正在使用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),

2 个答案:

答案 0 :(得分:1)

你可以在组件上设置ref属性,就像ref =“select1”

一样

然后您可以通过此方式调用焦点或模糊方法。$ refs

就像:这个。$ refs.select1.focus()

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

答案 1 :(得分:0)

如果您想在用户选择一个选项后隐藏下拉选项,只需在事件// init streamingContext val alertConfigRDD: RDD[String] = sc.textFile("alert-config.json") val alertConfig = alertConfigRDD.collect() for (config <- alertConfigs) { // spark streaming process: select window duration according to config details. } streamingContext.start() streamingContext.awaitTermination() 上重置远程数据。

示例:

当所选值更改时,请调用方法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>