表单元素的双向绑定
1. input受控绑定
使用bind关键字进行绑定,svelte通过bind关键字来完成类似v-model的双向绑定
- text
<input type="text" bind:value={formData.name} />
- checkbox
<input type="checkbox" bind:checked={formData.checkboxVal} />
- number
<input type="number" bind:checked={formData.number} />
- range
<input type="range" bind:checked={formData.rangeVal} />
- select
<script>
let questions = [
{ id: 1, text: 'question 1' },
{ id: 2, text: 'question 2' },
{