element的select加上filterable属性后就变成可搜索的选择框,但是手动输入的值在焦点变化后会消失。加入blur事件就可以解决这个问题。其中option标签属性不添加:key的情况下options最好不要出现相同的name。

html

<template>
    <el-select
      v-model="content"
      filterable
      @blur="selectBlur"
    >
        <el-option
          v-for="item in options"
          :label="item.name"
          :value="item.name"
        >
        </el-option>
    </el-select>
</template>

js

<script>
  export default{
    data () {
      return {
        options: [
          {name: 'aaa'},
          {name: 'bbb'},
          {name: 'ccc'}
        ],
        content: null,
      };
    },
    methods: {
      selectBlur(e) {
        this.inputContent = e.target.value
      },
    }
  }
</script>

 

GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:1 个月前 )
c345bb45 5 个月前
a07f3a59 * Update transition.md * Update table.md * Update transition.md * Update table.md * Update transition.md * Update table.md * Update table.md * Update transition.md * Update popover.md 5 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐