Sveltejs有条件地呈现html属性 [英] Sveltejs render html attribute conditionally
本文介绍了Sveltejs有条件地呈现html属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我只想自动聚焦此输入列表中的第一项:
{{#each codeInputs as codeInput, index}}
<input bind:value="inputCodes[index]" type="text" autofocus>
{{/each}}
属性autofocus
应该只存在于第一项。我可以使用index来检测第一个项目,但是autofocus="{{index===0}}"
呈现autofocus="true"
或"false"
,所以这不是我需要的。
另见https://github.com/sveltejs/svelte/issues/259
推荐答案
试试-it does work。Svelte不设置属性当它看到类似autofocus='{{xyz}}
的内容时,它设置属性-属性必须是字符串(这没有帮助),而属性可以是布尔值。
这篇关于Sveltejs有条件地呈现html属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文