最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - add custom part to v-autocomplete dropdown - Stack Overflow

programmeradmin0浏览0评论

I'm using vuetify's v-autocomplete component, and I'd like to add custom part to its dropdown (marked with red arrow on this screenshot: )

This is how my component looks like, so I'd like to add that part on top of items:

<v-autocomplete @change='selectedSearchedCandidate' append-icon="search" :loading="loading" :filter="v => v" :items="items" :search-input.sync="search" v-model="select" flat hide-no-data hide-details return-object placeholder="Search candidates">
    <template slot="selection" slot-scope="{ item, selected }">
        {{item.firstName}} {{item.lastName}}
    </template>
    <template slot="item" slot-scope="{ item, tile }">
        <v-list-tile-content>
            <p class='fullName'>{{item.firstName}} {{item.lastName}}</p>
            <p class='employer'>{{item.employer}}</p>
            <p class='phoneNumber grey--text'>{{formattedPhoneNumber(item.phoneNumber)}}</p>
        </v-list-tile-content>
    </template>
</v-autocomplete>

I'm using vuetify's v-autocomplete component, and I'd like to add custom part to its dropdown (marked with red arrow on this screenshot: https://prnt.sc/lm3vjc)

This is how my component looks like, so I'd like to add that part on top of items:

<v-autocomplete @change='selectedSearchedCandidate' append-icon="search" :loading="loading" :filter="v => v" :items="items" :search-input.sync="search" v-model="select" flat hide-no-data hide-details return-object placeholder="Search candidates">
    <template slot="selection" slot-scope="{ item, selected }">
        {{item.firstName}} {{item.lastName}}
    </template>
    <template slot="item" slot-scope="{ item, tile }">
        <v-list-tile-content>
            <p class='fullName'>{{item.firstName}} {{item.lastName}}</p>
            <p class='employer'>{{item.employer}}</p>
            <p class='phoneNumber grey--text'>{{formattedPhoneNumber(item.phoneNumber)}}</p>
        </v-list-tile-content>
    </template>
</v-autocomplete>
Share Improve this question asked Nov 23, 2018 at 16:17 kecmankecman 8533 gold badges16 silver badges39 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 15

You can use prepend-item slot. It will add, before the first item, whatever you want.

With your exemple, it should looks like this :

<v-autocomplete @change='selectedSearchedCandidate' append-icon="search" :loading="loading" :filter="v => v" :items="items" :search-input.sync="search" v-model="select" flat hide-no-data hide-details return-object placeholder="Search candidates">
    <v-list-tile
        slot="prepend-item"
        class="grey--text">
      {{ items.length }} candidates found
    </v-list-tile>
    <template slot="selection" slot-scope="{ item, selected }">
        {{item.firstName}} {{item.lastName}}
    </template>
    <template slot="item" slot-scope="{ item, tile }">
        <v-list-tile-content>
            <p class='fullName'>{{item.firstName}} {{item.lastName}}</p>
            <p class='employer'>{{item.employer}}</p>
            <p class='phoneNumber grey--text'>{{formattedPhoneNumber(item.phoneNumber)}}</p>
        </v-list-tile-content>
    </template>
</v-autocomplete>

Prepend and Append slot in Vuetify Documentation


Edit for V1.1.0+ : Those slots are available in v-autocomplete and v-combobox as they inherit from v-select.

Just modified this answer a bit. Instead of "v-list-tile-content", we can use "v-list-item-content" as the former one is giving console errors for 2.3.x and 2.4.x versions. @toodoo

发布评论

评论列表(0)

  1. 暂无评论