假设我有这个主要的应用程序:
import Field from '../components/Field.svelte';
var fields = [
{
id: 'Check',
type: 'CheckBox',
value: false,
},
{
id: 'Text'
}
];
var components = {};
$: console.log(components);
</script>
<style>
</style>
<form>
{#each fields as item}
<Field {...item} bind:bind={components[item.bind]} bind:this={components[item.id]}></Field>
{/each}
</form>
Run Code Online (Sandbox Code Playgroud)
我有两个组件,CheckBox和TextArea,都只实现 HTML 输入,而 Field 组件是这样实现的:
import CheckBox from './CheckBox.svelte';
import TextArea from './TextArea.svelte';
export let attributes = {};
export let type = 'TextArea';
export let value = '';
export let id;
export let bind; …Run Code Online (Sandbox Code Playgroud)