gpt4 book ai didi

javascript - 多个模板插槽的相同插槽内容

转载 作者:搜寻专家 更新时间:2023-10-30 22:12:48 26 4
gpt4 key购买 nike

在vuejs中,有没有办法不用复制粘贴就可以为多个slot设置相同的内容?

所以这样:

<base-layout>
<template slot="option">
<span :class="'flag-icon-' props.option.toLowerCase()" />{{ countriesByCode[props.option] }}
</template>

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

可以这样写:

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

非常感谢。

最佳答案

您可以尝试使用 v-for为此。

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

参见 working example .

关于javascript - 多个模板插槽的相同插槽内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54090950/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com