Vue-multiselect: Identical template slot for option & singleLabel

Created on 8 Jan 2019  路  2Comments  路  Source: shentao/vue-multiselect

It seems commonplace to me, that the option & singleLabel slots will eventually be the same.
I think there are no way in vue to add the same slot content for multiple template slots (as asked here, https://github.com/vuejs/vue/issues/9289).

May you consider adding a optionAndSingleLabel slot that, if present, is used twice and take place of both option and singleLabel?

Something like this country select box:
countries

If you got a better option to resolve this scenario, I'll be happy to hear it.
Thanks a lot.

Most helpful comment

Using v-for seems the more basic & simple option.
(from this stackoverflow answer: https://stackoverflow.com/a/54092116/535184)

<base-layout>
  <template :slot="slotName" v-for="slotName in ['option', 'singleLabel']">
    <span :class="'flag-icon-' + props.option.toLowerCase()" />{{ countriesByCode[props.option] }}
  </template>
</base-layout>

All 2 comments

Using v-for seems the more basic & simple option.
(from this stackoverflow answer: https://stackoverflow.com/a/54092116/535184)

<base-layout>
  <template :slot="slotName" v-for="slotName in ['option', 'singleLabel']">
    <span :class="'flag-icon-' + props.option.toLowerCase()" />{{ countriesByCode[props.option] }}
  </template>
</base-layout>

I am here for the second time, so I am putting complete version of code for future me 馃榿 including slot-scope="props" to have props available. (credit: SO comment)

<base-layout>
  <template :slot="slotName" v-for="slotName in ['option', 'singleLabel']" slot-scope="props">
    <span :class="'flag-icon-' + props.option.toLowerCase()" />{{ countriesByCode[props.option] }}
  </template>
</base-layout>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

shsmad picture shsmad  路  3Comments

katranci picture katranci  路  3Comments

zachleigh picture zachleigh  路  3Comments

dmitov picture dmitov  路  4Comments

andreasvirkus picture andreasvirkus  路  3Comments