Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/select/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,20 +491,23 @@ export default {
某些场景下,你会需要根据用户的输入从服务器端获取相关选项。你可以指定 `filter` 函数返回一个 `Promise` 即可。使用 `filter` 函数时,可以通过 `filterThrottle` 指定最小触发间隔,其默认值为 `0`。

```html
<!-- multiple -->
<c-select
v-model="choice"
:options="options"
:filter="search"
:filterThrottle="1000"
autocomplete
@change="onChange"
multiple
>
</c-select>

<script>
const rdn = _ => Math.random().toString(36).substr(-3)
let num = 0
const defaultOptions = ['option 1', 'option 2', 'option 3']
.map(value => ({label: value, value}))
.map(value => ({label: value, value: num++}))
export default {
data () {
return {
Expand Down
7 changes: 6 additions & 1 deletion src/components/select/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ export default {
selectedValues () {
return this.selectedOptions.map(option => option.value)
},
selectedLabel () {
return this.selectedOptions.map(option => option.label)
},
showPlaceholder () {
const empty = !this.selectedOptions.length
return empty && !this.isOpen
Expand Down Expand Up @@ -502,7 +505,9 @@ export default {

emitChange () {
const value = this.multiple ? this.selectedValues : this.selectedValues[0]
this.$emit('change', value)
const label = this.multiple ? this.selectedLabel : this.selectedLabel[0]
console.log(value, label)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console 去掉。。。

this.$emit('change', value, label)
}
}
}
Expand Down