首次尝试:
<button type="submit" class="button" {{#if isDirty(item)}}disabled{{/if}}>Save2</button>
在编译期间导致错误:
bundling...
(svelte plugin) Error: (28:75) Expected >
26: <div class="row">
27: <!-- FIXME Can't set an attribute dynamically? -->
28: <button type="submit" class="button" {{#if isDirty(item)}}disabled{{/if}}>Save2</button>
^
我能想出的最好的结果:
{{#if isDirty(item)}}
<button type="submit" class="button" disabled>Save</button>
{{else}}
<button type="submit" class="button">Save</button>
{{/if}}
答案 0 :(得分:1)
Svelte'修复'HTML,以便disabled
属性(和其他布尔属性)表现得更加明智:
<button type="submit" class="button" disabled='{{isDirty(item)}}'>Save</button>