Created
April 10, 2024 20:03
-
-
Save helabenkhalfallah/a594a826905fdca1d62a2f9c9f3e633e to your computer and use it in GitHub Desktop.
Child Component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- Child.svelte --> | |
| <!-- Script Section --> | |
| <script> | |
| // Import necessary functions from Svelte | |
| import { createEventDispatcher } from 'svelte'; | |
| // Create a dispatcher for emitting custom events | |
| const dispatch = createEventDispatcher(); | |
| // Define variables to store form data | |
| let username = ''; | |
| let email = ''; | |
| let password = ''; | |
| // Function to handle form submission | |
| const handleSubmit = () => { | |
| // Emit a custom event named 'submit' with form data | |
| dispatch('submit', { username, email, password }); | |
| }; | |
| </script> | |
| <!-- Form Markup --> | |
| <form on:submit|preventDefault={handleSubmit}> | |
| <!-- Input fields for username, email, and password --> | |
| <label> | |
| Username: | |
| <input type="text" bind:value={username} /> | |
| </label> | |
| <label> | |
| Email: | |
| <input type="email" bind:value={email} /> | |
| </label> | |
| <label> | |
| Password: | |
| <input type="password" bind:value={password} /> | |
| </label> | |
| <!-- Button to submit the form --> | |
| <button type="submit">Submit</button> | |
| </form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment