Updated April 4, 2023
Introduction to Svelte Components
- The svelte components are similar to the “react” or “vue” framework component to create a web application.
- The svelte components are reusable parts of the code to combine HTML, CSS, and JavaScript code.
- The svelte component is self-contained code using summarize basic web technologies like HTML, JavaScript, and CSS.
- The svelte component is a JavaScript framework to create fast applications and part of the interactive interfaces.
- The svelte component is similar to the other web application component and it works on the “svelte” extension file.
- The svelte component divided web applications into small parts to make an easy and sorted application.
- The svelte component creates small user interfaces to remove the complexity of the web application using the svelte framework.
- The svelte framework is component-based architecture and different components use for fast, sorted, and user-friendly applications.
Svelte Components
- The svelte framework is based on the component. This framework uses the different components to create small user interfaces.
- The different component creates header, footer, side navigation bar, and main content of the application.
- The component is placed in a script tag, main tag, and style tag in the svelte file.
- The root component is the main component of the svelte framework. This component creates by file with the “svelte” extension.
Root component
Example: Application.svelte
The root component divides into three parts of the interfaces.
- Header component
- Footer component
- Content component
The content component divides into two parts.
- Modal component
- Sidebar component
Root component
- The root component stores all components in one file.
- This component categorizes with different interfaces.
- The root component creates using HTML, CSS, and JavaScript tags.
- Example: Application.svelte
Header component
- The header component creates the header of the web application.
- The header component is used for the top side of the application.
- You can add multiple tabs and buttons in the header component.
- Example: Headers. svelte
Footer component
- The footer component creates the footer of the web application.
- The header component is used for the bottom side of the application.
- You can add multiple tabs and buttons in the footer component.
- You can add content and the required links to the application.
- Example: Footers. svelte
Content component
- The content component creates the core part of the web application.
- The content component is used for the middle part or center part of the application.
- You can add multiple tabs and buttons in the content component.
- You can add content and the required links to the application.
- The other advanced function and tools are used to connect with the user.
- This component creates model and sidebar components at the middle part of the application.
- Example: Contents.svelte
Modal component
- The modal component is part of the content component.
- This component is used for the center part of the web application.
- The modal component creates components and stores other tools or components.
- You can add multiple tabs and buttons in the content component.
- You can add content and the required links to the application.
- The other advanced function and tools are used to connect with the user.
- Example: Modals.svelte
sidebar component
- The root component stores sidebar components in one file.
- The sidebar component is part of the content component.
- This component is used for the left or right part of the web application.
- The modal component creates components and stores other tools or components.
- You can add multiple tabs and buttons in the content component.
- You can add content and the required links to the application.
- The other advanced function and tools are used to connect with the user.
- Example: Sidebar.svelte
Basic about Root (App) components
- The root component stores above all components in one file.
- This component is used in the core file or used another file and imports it.
- The root (App) component file mainly contains three web technology tags.
- The JavaScript technology is representing or using <script> tag.
- The HTML technology is representing or using markup tags such as a <P>, <div> and etc.
- The CSS technology is representing or using <style> tag.
- The svelte file uses tags in order to JavaScript, HTML, and CSS.
<script> write JavaScript code here… </script>
<div> write HTML code here… </div>
<style> write CSS code or style here… </style>
Example:
<script> let topic = "svelte" </script>
<div> learn {topic}. </div>
<style> div{color : blue; } </style>
Output:
- The JavaScript creates variables with the topic name.
- The HTML creates the “div” component.
- This component contains text with a JavaScript variable.
- The CSS style contains a markup tag component which “div” component.
Nested component components
- The root component stores all components in one file.
- The svelte creates another component file.
- This file connects with the root component file with the import tag in the script.
- You can create multiple component files like header, footer, content file.
- The above files must connect with the root/App component file.
<script>
import file_name from './path/file_name.svelte';
</script>
Root component
- The root component stores all components in one file.
- This component categorizes with different interfaces.
- The root component creates using HTML, CSS, and JavaScript tags.
- Example: Application. svelte
Modal component
- The component is used for the center part of the web application.
- The modal component creates components and stores other tools or components.
- Example: Modals.svelte
Example:
File name: Application.svelte
<script>
import Modals from './Modals.svelte';
let topic = "svelte"
</script>
<Modals/>
<div> learn {topic}. </div>
<style> div{color : blue; } </style>
File name: Modals.svelte
<h2> svelte tutorial </h2>
Output:
- The javascript uses the “import” function for a nested component.
- Another component connects with the root component.
- The JavaScript creates variables with the topic name.
- The HTML creates the “div” component.
- This component contains text with a JavaScript variable.
- The CSS style contains a markup tag component which “div” component.
Conclusion
- The svelte components create multiple interfaces and connect with one link.
- This component uses to create a user-friendly, attractive, and easy web application.
- The svelte component helps to reduce coding complexity and load.
Recommended Articles
This is a guide to Svelte Components. Here we discuss the definition, various Svelte Components respectively. You may also have a look at the following articles to learn more –