If we use selection slot
to customize the chip as we want like @YomS. show above, we cannot use chips
and deletable-chips
props to make that chip deletable.
For anyone also need to implement deletable-chips in selection slot, here my snippet:
<template>
<v-select
v-model="styleSelection" // Linking that v-select to one array
clearable
multiple
:items="travelStyles"
label="Travel Style"
>
<template #selection="{ item }">
<v-chip
color="primary"
close
@click:close="deleteChip(item, styleSelection)" // call a method deleteChip
>{{ item }}</v-chip
>
</template>
</v-select>
</template>
<script>
export default {
data: () => ({
styleSelection: [],
travelStyles: [
'Discovery',
'Family',
'In-depth Cultural',
'Historical',
'Food & Culinary',
'Adventure',
'Beach',
'Hiking & Trekking',
'Bicycle',
'Sightseeing',
'Boat',
'River Cruise',
'Ocean Cruise',
],
}),
methods: {
deleteChip(itemNeedToRemove, array) {
for (let i = 0; i < array.length; i += 1) {
if (array[parseInt(i, 10)] === itemNeedToRemove) {
array.splice(i, 1);
}
}
},
},
};
</script>
Beside Selects v-select
, it also works with Autocomplete v-autocompletes
, the snippet is exactly the same.
If you want to customize the chip color and make it deletable in V-autocompletes, you can take the look on the code below:
<v-autocomplete
v-model="citySelection"
clearable
multiple
:items="city"
label="Where do you want to go?"
:search-input.sync="search"
@change="search = ''"
>
<template #selection="{ item }">
<v-chip
close
color="primary"
@click:close="deleteChip(item, citySelection)"
>{{ item }}</v-chip
>
</template>
</v-autocomplete>