Condition for svelte tag attributes
问题 How to add attribute inline, without needing to duplicate the anchor tag ? https://svelte.dev/repl/a4e072ca670b481cb5d0360d01d07f27?version=3.12.1 <ul> {#each menu as item} <li> <a {item.prefetch ? 'rel=prefetch' : ''} href="{item.link}"> {item.title} </a> </li> {/each} </ul> I have Error compiling component when: {item.prefetch ? 'rel=prefetch' : ''} Next code works, but not quite what I need: rel={item.prefetch ? 'prefetch' : ''} 回答1: Try using undefined e.g. rel={item.prefetch ? 'prefetch'