Skip to content

Commit d6c99ae

Browse files
authored
feat: 为 el-select 添加 extra 插槽 (#66)
1 parent af8b9aa commit d6c99ae

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

examples/docs/zh-CN/select.md

+60
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,65 @@
515515
```
516516
:::
517517

518+
### 扩展插槽
519+
520+
选项列表底部扩展内容
521+
:::demo 扩展插槽可以插入自己需要的功能按钮。
522+
```html
523+
<template>
524+
  <div>
525+
    <el-select v-model="value" placeholder="请选择">
526+
      <el-option
527+
        v-for="item in cities"
528+
        :key="item.value"
529+
        :label="item.label"
530+
        :value="item.value">
531+
      </el-option>
532+
      <div slot="extra">
533+
        <el-button type="text" @click="handleRefresh" style="width: 100%;">
534+
刷新城市列表
535+
</el-button>
536+
      </div>
537+
    </el-select>
538+
  </div>
539+
</template>
540+
541+
<script>
542+
  export default {
543+
    data() {
544+
      return {
545+
        cities: [{
546+
          value: 'Beijing',
547+
          label: '北京'
548+
        }, {
549+
          value: 'Shanghai',
550+
          label: '上海'
551+
        }, {
552+
          value: 'Nanjing',
553+
          label: '南京'
554+
        }, {
555+
          value: 'Chengdu',
556+
          label: '成都'
557+
        }, {
558+
          value: 'Shenzhen',
559+
          label: '深圳'
560+
        }, {
561+
          value: 'Guangzhou',
562+
          label: '广州'
563+
        }],
564+
        value: ''
565+
      };
566+
    },
567+
    methods: {
568+
      handleRefresh() {
569+
        // 重新请求获取 cities 数据
570+
      },
571+
    }
572+
  }
573+
</script>
574+
```
575+
:::
576+
518577
:::tip
519578
如果 Select 的绑定值为对象类型,请务必指定 `value-key` 作为它的唯一性标识。
520579
:::
@@ -565,6 +624,7 @@
565624
|| Option 组件列表 |
566625
| prefix | Select 组件头部内容 |
567626
| empty | 无选项时的列表 |
627+
| extra | 选项列表底部扩展内容 |
568628

569629
### Option Group Attributes
570630
| 参数 | 说明 | 类型 | 可选值 | 默认值 |

packages/select/src/select.vue

+3
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@
122122
</el-option>
123123
<slot></slot>
124124
</el-scrollbar>
125+
<template v-if="$slots.extra">
126+
<slot name="extra"></slot>
127+
</template>
125128
<template v-if="emptyText && (!allowCreate || loading || (allowCreate && options.length === 0 ))">
126129
<slot name="empty" v-if="$slots.empty"></slot>
127130
<p class="el-select-dropdown__empty" v-else>

0 commit comments

Comments
 (0)