有没有更简单的方法来编写以下复选框组件:
<script>
export let disabled = false;
</script>
{#if disabled}
<label class="checkbox" disabled>
<input type="checkbox" {disabled} />
<slot></slot>
</label>
{:else}
<label class="checkbox">
<input type="checkbox" {disabled} />
<slot></slot>
</label>
{/if}
Having <label disabled="false">
不可接受,因为 Bulma 有一个 CSS 类.checkbox[disabled]
.
disabled || null
(or disabled || undefined
)就可以解决这个问题:
<label class="checkbox" disabled={disabled || null}>
<input type="checkbox" {disabled} />
<slot></slot>
</label>
来自docs https://svelte.dev/docs#template-syntax-attributes-and-props:
... [包含属性,除非它们的值是nullish https://developer.mozilla.org/en-US/docs/Glossary/Nullish
(null
or undefined
).
<input required={false} placeholder="This input field is not required">
<div title={null}>This div has no title attribute</div>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)