我认为是因为模板标签中的第一个元素,但我做了一个扭曲来得到你想要的,我添加了一个,key
因为它在x-for
. 现在我在 中返回了数组索引for in loop
,然后绑定一个类来检查索引是否应该添加rounded-l-md
到它。
<!-- Include CDN JavaScript -->
<script src="https://unpkg.com/tailwindcss-jit-cdn"></script>
<script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
<!-- Specify a custom TailwindCSS configuration -->
<script type="tailwind-config">
{
variants: {
extend: {
borderRadius: ['last, first'],
},
},
}
</script>
<div class="p-10" x-data="{ timeframes: [{id: 1, n: '1d'}, {id: 2, n: '1w'}, {id: 3, n: '1y'}] }">
<span class="relative z-0 inline-flex shadow-sm rounded-md">
<template x-for="(timeframe, index) in timeframes" :key="timeframe.id">
<button type="button" class="-ml-px relative inline-flex items-center px-4 py-2 last:rounded-r-md border border-gray-300 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 focus:z-10 focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500"
:class="{'rounded-l-md' : !index}"
>
<span x-text="timeframe.n"></span>
</button>
</template>
</span>
</div>