在加载具有输入字段的组件后,我该如何聚焦到那个特定的字段?
TextField.svelte
TextField.svelte
<script>
export let label = ''
export let name = ''
export let placeholder = ''
export let value = ''
</script>
<div class="field">
<label for={name}>{label}</label>
<input {placeholder} type="text" {name} bind:value={value} >
<slot></slot>
</div>
App.svelte
<script>
import TextField from './TextField'
import {onMount} from 'svete'
onMount(() => {
// This line is funny.. I know
document.querySelector('[name="firstname"]').focus()
})
</script>
<TextField label="First Name" name="firstname" />