I'm usign the Select2 component from VueJS https://www.npmjs.com/package/vue-select2
import VueSelect2 from "vue-select2";
I want to add an option to search in the same list that is displayed, as the single select feature, not in the same input.
Why in the list? Because I will replace the selected items with a text "N options selected" and avoid searching from the input itself.
Other example I need is something like this: https://semantic-ui-vue.github.io/#/modules/dropdown
I found a similar question in Enable select2 multi-select search box, but I'm not sure if this exact I need, because it does not show an image, also it is not an implementation in VueJS and I don't know how to implement it. See the following image with the response by HolaJan.
Finally, I looked for the documentation of the Select2 for VueJS this part

but it didn't work for me either.
Code
<template>
<select
id="select2"
:name="name"
class="form-control"
:searchable="true"
></select>
</template>
<script>
import VueSelect2 from "vue-select2";
export default {
name: "Select2",
props: {
name: {
type: String,
},
value: {
type: Array,
default: () => [],
},
callbackUrl: {
type: String,
},
placeholder: {
type: String,
default: "All",
},
multiple: {
type: Boolean,
default: true,
},
resultsHandler: {
type: Function,
default: (data) => data,
},
parameterHandler: {
type: Function,
default: (params) => ({
searchText: params.term,
page: params.page,
}),
},
},
mounted: function () {
var self = this;
var placeholderDefault = this.placeholder;
var options = {
placeholder: this.placeholder,
allowClear: true,
ajax: {
url: self.callbackUrl,
dataType: "json",
type: "POST",
cache: false,
data: function (params) {
return self.parameterHandler(params);
},
processResults: function (data) {
return self.resultsHandler(data);
},
},
multiple: this.multiple,
closeOnSelect: false,
templateResult: function formatCountry(country) {
if (!country.id) {
return country.text;
}
var baseUrl = "https://cdn.ip2location.com/assets/img/flags/";
var $country = $(
'<span><img src="' +
baseUrl +
country.id.toLowerCase() +
'.png" class="img-flag" /> ' +
country.text.trim() +
"</span>"
);
return $country;
},
templateSelection: function formatCountry(country) {
if (!country.id) {
return country.text;
}
var baseUrl = "https://cdn.ip2location.com/assets/img/flags/";
var $country = $(
'<span><img src="' +
baseUrl +
country.id.toLowerCase() +
'.png" class="img-flag" /> ' +
country.text.trim() +
"</span>"
);
return $country;
},
$(this.$el).select2(options);
$(this.$el).empty();
for (var i = 0; i < self.$props.value.length; i++) {
var value = self.$props.value[i];
$(this.$el)
.append(new Option(value.Name, value.ID, true, true))
.trigger("change");
}
},
};
</script>



