2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-22 10:30:34 +03:00

adding custom template for option and selected-option

This commit is contained in:
Edwin de Jonge
2017-05-02 10:20:56 +02:00
parent 072bf4160d
commit 7c6217bc47
3 changed files with 16 additions and 2 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
{ {
"presets": ["es2015", "stage-2"], "presets": ["es2015", "stage-2"],
"plugins": ["transform-runtime"], "plugins": ["transform-runtime", "transform-object-rest-spread"],
"comments": false "comments": false
} }
+10
View File
@@ -39,6 +39,16 @@
<v-select placeholder="multiple, closeOnSelect=false" multiple :close-on-select="false" :options="['cat', 'dog', 'bear']"></v-select> <v-select placeholder="multiple, closeOnSelect=false" multiple :close-on-select="false" :options="['cat', 'dog', 'bear']"></v-select>
<v-select placeholder="unsearchable" :options="options" :searchable="false"></v-select> <v-select placeholder="unsearchable" :options="options" :searchable="false"></v-select>
<v-select placeholder="search github.." label="full_name" @search="search" :options="ajaxRes"></v-select> <v-select placeholder="search github.." label="full_name" @search="search" :options="ajaxRes"></v-select>
<v-select placeholder="custom option template" :options="options" multiple>
<template slot="selected-option" scope="option">
<img :src='"https://www.kidlink.org/icons/f0-" + option.value.toLowerCase() + ".gif"'/>
{{option.label}}
</template>
<template slot="option" scope="option">
<img :src='"https://www.kidlink.org/icons/f0-" + option.value.toLowerCase() + ".gif"'/>
{{option.label}} ({{option.value}})
</template>
</v-select>
</div> </div>
</body> </body>
+5 -1
View File
@@ -270,7 +270,9 @@
<div ref="toggle" @mousedown.prevent="toggleDropdown" class="dropdown-toggle"> <div ref="toggle" @mousedown.prevent="toggleDropdown" class="dropdown-toggle">
<span class="selected-tag" v-for="option in valueAsArray" v-bind:key="option.index"> <span class="selected-tag" v-for="option in valueAsArray" v-bind:key="option.index">
{{ getOptionLabel(option) }} <slot name="selected-option" v-bind="option">
{{ getOptionLabel(option) }}
</slot>
<button v-if="multiple" @click="deselect(option)" type="button" class="close"> <button v-if="multiple" @click="deselect(option)" type="button" class="close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
@@ -305,7 +307,9 @@
<ul ref="dropdownMenu" v-if="dropdownOpen" class="dropdown-menu" :style="{ 'max-height': maxHeight }"> <ul ref="dropdownMenu" v-if="dropdownOpen" class="dropdown-menu" :style="{ 'max-height': maxHeight }">
<li v-for="(option, index) in filteredOptions" v-bind:key="index" :class="{ active: isOptionSelected(option), highlight: index === typeAheadPointer }" @mouseover="typeAheadPointer = index"> <li v-for="(option, index) in filteredOptions" v-bind:key="index" :class="{ active: isOptionSelected(option), highlight: index === typeAheadPointer }" @mouseover="typeAheadPointer = index">
<a @mousedown.prevent="select(option)"> <a @mousedown.prevent="select(option)">
<slot name="option" v-bind="option">
{{ getOptionLabel(option) }} {{ getOptionLabel(option) }}
</slot>
</a> </a>
</li> </li>
<li v-if="!filteredOptions.length" class="no-options"> <li v-if="!filteredOptions.length" class="no-options">