<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hany Taha</title>
    <description>The latest articles on DEV Community by Hany Taha (@hanytaha61).</description>
    <link>https://dev.to/hanytaha61</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F243790%2Fe62347f8-5653-436a-93a0-66356b1887b7.jpeg</url>
      <title>DEV Community: Hany Taha</title>
      <link>https://dev.to/hanytaha61</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hanytaha61"/>
    <language>en</language>
    <item>
      <title>Mastering Vue 3: A Comprehensive Guide to Building Modern Web Applications &lt;Part 14 /&gt;</title>
      <dc:creator>Hany Taha</dc:creator>
      <pubDate>Tue, 12 Mar 2024 22:03:03 +0000</pubDate>
      <link>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4bhi</link>
      <guid>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4bhi</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Content:&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-1--c75"&gt;1. Mastering Vue 3 - Part 1 [Introduction and key features]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-2--1k0l"&gt;2. Mastering Vue 3 - Part 2 [Benefits of using Vue 3 for web development]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-3--fde"&gt;3. Mastering Vue 3 - Part 3 [Template syntax in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-19c0"&gt;4. Mastering Vue 3 - Part 4 [Reactivity Fundamentals]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-16g"&gt;5. Mastering Vue 3 - Part 5 [Class and Style Bindings]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-1c6e"&gt;6. Mastering Vue 3 - Part 6 [Lifecycle Hooks]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3nnd"&gt;7. Mastering Vue 3 - Part 7 [Understanding components]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-17ge"&gt;8. Mastering Vue 3 - Part 8 [Installing Vue project and file structure]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5d1p"&gt;9. Mastering Vue 3 - Part 9 [Vue Router in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4ig2"&gt;10. Mastering Vue 3 - Part 10 [Animation in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-53gh"&gt;11. Mastering Vue 3 - Part 11 [State Management with Pinia]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;12. Mastering Vue 3 - Part 12 [Teleport in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3m94"&gt;13. Mastering Vue 3 - Part 13 [Working with API Calls ]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;14. Mastering Vue 3 - Part 14 [Forms and Form Validation ]&lt;/strong&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Forms and Form Validation
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Handling Forms and Form Submissions in Vue 3:&lt;/strong&gt;&lt;br&gt;
In Vue 3, handling forms and form submissions involves using the v-model directive to bind form inputs to data properties in your component. You can use the &lt;code&gt;v-model&lt;/code&gt; directive to create two-way data binding, allowing you to easily get and set the values of form inputs. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;submit=&lt;/span&gt;&lt;span class="s"&gt;"submitForm"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;v-model=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;v-model=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;

  &lt;span class="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;submitForm&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// Handle form submission logic here&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Form submitted!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we bind the &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;email&lt;/code&gt; input fields to the component's data using &lt;code&gt;v-model&lt;/code&gt;. When the form is submitted, the &lt;code&gt;submitForm&lt;/code&gt; method is called, and the input values can be accessed using &lt;code&gt;this.name&lt;/code&gt; and &lt;code&gt;this.email&lt;/code&gt;.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Implementing Form Validation and Error Handling:&lt;/strong&gt;&lt;br&gt;
To implement form validation and error handling, you can use various techniques such as computed properties, watchers, or form validation libraries. Here's an example using computed properties to validate the form fields:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;submit=&lt;/span&gt;&lt;span class="s"&gt;"submitForm"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;v-model=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt; &lt;span class="na"&gt;:class=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;{ 'is-invalid': !isNameValid }" /&amp;gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;v-model=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;:class=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;{ 'is-invalid': !isEmailValid }" /&amp;gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;

  &lt;span class="na"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;isNameValid&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nf"&gt;isEmailValid&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// Add your email validation logic here&lt;/span&gt;
      &lt;span class="c1"&gt;// For example, you can use a regular expression&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;emailRegex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/^&lt;/span&gt;&lt;span class="se"&gt;\S&lt;/span&gt;&lt;span class="sr"&gt;+@&lt;/span&gt;&lt;span class="se"&gt;\S&lt;/span&gt;&lt;span class="sr"&gt;+&lt;/span&gt;&lt;span class="se"&gt;\.\S&lt;/span&gt;&lt;span class="sr"&gt;+$/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;emailRegex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;

  &lt;span class="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;submitForm&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isNameValid&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isEmailValid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Handle form submission logic here&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Form submitted!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Handle form validation errors&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Form validation error!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we use computed properties &lt;code&gt;isNameValid&lt;/code&gt; and &lt;code&gt;isEmailValid&lt;/code&gt; to validate the &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;email&lt;/code&gt; fields, respectively. We apply the &lt;code&gt;'is-invalid'&lt;/code&gt; class to the input fields if the validation fails.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Working with Form Libraries and Custom Form Components:&lt;/strong&gt;&lt;br&gt;
Vue 3 has several form libraries available that provide advanced form handling and validation features. Some popular options include VeeValidate, Vuelidate, and Vuetify. These libraries can simplify form validation, error handling, and provide additional UI components for building forms.&lt;/p&gt;

&lt;p&gt;Alternatively, you can create your own custom form components using Vue's composition API. By encapsulating form logic within reusable components, you can create a more modular and maintainable form solution. For example, you can create a custom &lt;code&gt;TextInput&lt;/code&gt; component that handles form validation internally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;:type=&lt;/span&gt;&lt;span class="s"&gt;"type"&lt;/span&gt; &lt;span class="na"&gt;:value=&lt;/span&gt;&lt;span class="s"&gt;"value"&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;input=&lt;/span&gt;&lt;span class="s"&gt;"updateValue"&lt;/span&gt; &lt;span class="na"&gt;:class=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;{ 'is-invalid': !isValid }" /&amp;gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;v-if=&lt;/span&gt;&lt;span class="s"&gt;"!isValid"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"error-message"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;errorMessage&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;validation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;errorMessage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Invalid value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;

  &lt;span class="na"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;isValid&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;validation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;

  &lt;span class="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;updateValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;$emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we create a &lt;code&gt;TextInput&lt;/code&gt; component that accepts props for &lt;code&gt;type&lt;/code&gt;, &lt;code&gt;value&lt;/code&gt;, &lt;code&gt;validation&lt;/code&gt;, and &lt;code&gt;errorMessage&lt;/code&gt;. The component validates the input value based on the provided validation function, and displays an error message if the validation fails.&lt;/p&gt;




&lt;p&gt;By utilizing form libraries or creating custom form components, you can enhance the functionality and reusability of your forms in Vue 3. Choose the approach that best suits your project's requirements and complexity.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>vue</category>
    </item>
    <item>
      <title>Mastering Vue 3: A Comprehensive Guide to Building Modern Web Applications &lt;Part 13 /&gt;</title>
      <dc:creator>Hany Taha</dc:creator>
      <pubDate>Thu, 07 Mar 2024 17:30:30 +0000</pubDate>
      <link>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3m94</link>
      <guid>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3m94</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Content:&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-1--c75"&gt;1. Mastering Vue 3 - Part 1 [Introduction and key features]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-2--1k0l"&gt;2. Mastering Vue 3 - Part 2 [Benefits of using Vue 3 for web development]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-3--fde"&gt;3. Mastering Vue 3 - Part 3 [Template syntax in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-19c0"&gt;4. Mastering Vue 3 - Part 4 [Reactivity Fundamentals]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-16g"&gt;5. Mastering Vue 3 - Part 5 [Class and Style Bindings]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-1c6e"&gt;6. Mastering Vue 3 - Part 6 [Lifecycle Hooks]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3nnd"&gt;7. Mastering Vue 3 - Part 7 [Understanding components]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-17ge"&gt;8. Mastering Vue 3 - Part 8 [Installing Vue project and file structure]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5d1p"&gt;9. Mastering Vue 3 - Part 9 [Vue Router in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4ig2"&gt;10. Mastering Vue 3 - Part 10 [Animation in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-53gh"&gt;11. Mastering Vue 3 - Part 11 [State Management with Pinia]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;12. Mastering Vue 3 - Part 12 [Teleport in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;13. Mastering Vue 3 - Part 13 [Working with API Calls ]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4bhi"&gt;14. Mastering Vue 3 - Part 14 [Forms and Form Validation ]&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Working with API Calls
&lt;/h2&gt;

&lt;p&gt;Working with API Calls in Vue 3 can be done using two popular methods: using Axios or using the built-in Fetch API. Let's explore both methods:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Using Axios:&lt;/strong&gt;&lt;br&gt;
Axios is a widely used and powerful HTTP client library that simplifies making API calls in Vue applications. To use Axios in your Vue 3 project, follow these steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Axios: Start by installing Axios via npm or yarn:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Import Axios: In your component file, import Axios:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Making API Requests: Now, you can make various types of API requests using Axios, such as GET, POST, PUT, DELETE, etc. Here's an example of making a GET request:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.example.com/data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// handle success&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// handle error&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In this example, we use &lt;code&gt;axios.get()&lt;/code&gt; to make a GET request to &lt;code&gt;https://api.example.com/data&lt;/code&gt;. The response data is accessed in the &lt;code&gt;.then()&lt;/code&gt; callback, and any errors are handled in the &lt;code&gt;.catch()&lt;/code&gt; callback.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Using Fetch:&lt;/strong&gt;&lt;br&gt;
Fetch is a native JavaScript API for making HTTP requests. It is built into modern browsers and does not require any additional installations. Here's an example of making a GET request using Fetch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.example.com/data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Request failed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// handle response data&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// handle error&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we use the &lt;code&gt;fetch()&lt;/code&gt; function to make a GET request to &lt;code&gt;https://api.example.com/data&lt;/code&gt;. We check if the response was successful using &lt;code&gt;response.ok&lt;/code&gt;, and then parse the response data using &lt;code&gt;response.json()&lt;/code&gt;. The response data is then available in the second &lt;code&gt;.then()&lt;/code&gt; callback, and any errors are handled in the &lt;code&gt;.catch()&lt;/code&gt; callback.&lt;/p&gt;

&lt;p&gt;Both Axios and Fetch can be used to make API calls in Vue 3. Choose the method that best fits your project requirements and preferences. Axios offers more features and flexibility, while Fetch is built-in and requires no additional dependencies.&lt;/p&gt;

&lt;p&gt;There are also some more information about working with API calls in Vue 3 using Axios and Fetch:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Handling Response Data:&lt;/strong&gt;&lt;br&gt;
When making API calls, both Axios and Fetch return Promises that allow you to handle the response data. In Axios, the response data is accessed through the &lt;code&gt;response.data&lt;/code&gt; property. With Fetch, you can use methods like &lt;code&gt;response.json()&lt;/code&gt; to parse the response body as JSON, &lt;code&gt;response.text()&lt;/code&gt; to get the response body as text, or &lt;code&gt;response.blob()&lt;/code&gt; to handle binary data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Sending Request Headers:&lt;/strong&gt;&lt;br&gt;
Both Axios and Fetch allow you to send custom headers along with your API requests. In Axios, you can set request headers using the &lt;code&gt;headers&lt;/code&gt; property in the request configuration object. With Fetch, you can use the &lt;code&gt;Headers&lt;/code&gt; constructor and the &lt;code&gt;headers&lt;/code&gt; property in the &lt;code&gt;fetch()&lt;/code&gt; function options to set the headers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Handling Errors:&lt;/strong&gt;&lt;br&gt;
When dealing with API calls, it's important to handle errors properly. In Axios, you can use the &lt;code&gt;.catch()&lt;/code&gt; method to handle any errors that occur during the request. Axios also provides an &lt;code&gt;error&lt;/code&gt; object with additional information about the error. With Fetch, you can check the &lt;code&gt;response.ok&lt;/code&gt; property within the &lt;code&gt;.then()&lt;/code&gt; method to determine if the request was successful. If not, you can throw an error or handle it accordingly in the &lt;code&gt;.catch()&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Canceling Requests (Axios):&lt;/strong&gt;&lt;br&gt;
Axios provides built-in support for canceling requests. You can create a cancel token using the &lt;code&gt;CancelToken&lt;/code&gt; class and pass it as a config option to the Axios request. Then, you can call the &lt;code&gt;cancel()&lt;/code&gt; method on the cancel token object to cancel the request if needed. This can be useful when dealing with scenarios like user-initiated request cancellations or cleanup when a component is unmounted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Interceptors (Axios):&lt;/strong&gt;&lt;br&gt;
Axios allows you to intercept requests and responses using interceptors. Interceptors provide a way to modify or handle requests or responses globally. You can use &lt;code&gt;axios.interceptors.request.use()&lt;/code&gt; to intercept requests before they are sent, and &lt;code&gt;axios.interceptors.response.use()&lt;/code&gt; to intercept responses before they are handled. This can be useful for tasks like adding authentication headers, handling error responses, or performing request/response transformations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Cross-Origin Requests:&lt;/strong&gt;&lt;br&gt;
Both Axios and Fetch support cross-origin requests, which means you can make API calls to different domains or ports. However, in certain cases, you may encounter cross-origin resource sharing (CORS) restrictions imposed by the server. These restrictions can be configured on the server-side to allow specific domains or HTTP methods. If you run into CORS issues, you may need to configure the server accordingly.&lt;/p&gt;

&lt;p&gt;Overall, both Axios and Fetch are powerful tools for making API calls in Vue 3. They provide flexibility, error handling, and support for various request types. Choose the one that best fits your project's needs and consider factors like ease of use, additional features, and community support.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>vue</category>
    </item>
    <item>
      <title>Mastering Vue 3: A Comprehensive Guide to Building Modern Web Applications &lt;Part 12 /&gt;</title>
      <dc:creator>Hany Taha</dc:creator>
      <pubDate>Fri, 01 Mar 2024 19:45:44 +0000</pubDate>
      <link>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64</link>
      <guid>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Content:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-1--c75"&gt;Mastering Vue 3 - Part 1 [Introduction and key features]&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-2--1k0l"&gt;2. Mastering Vue 3 - Part 2 [Benefits of using Vue 3 for web development]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-3--fde"&gt;3. Mastering Vue 3 - Part 3 [Template syntax in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-19c0"&gt;4. Mastering Vue 3 - Part 4 [Reactivity Fundamentals]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-16g"&gt;5. Mastering Vue 3 - Part 5 [Class and Style Bindings]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-1c6e"&gt;6. Mastering Vue 3 - Part 6 [Lifecycle Hooks]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3nnd"&gt;7. Mastering Vue 3 - Part 7 [Understanding components]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-17ge"&gt;8. Mastering Vue 3 - Part 8 [Installing Vue project and file structure]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5d1p"&gt;9. Mastering Vue 3 - Part 9 [Vue Router in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4ig2"&gt;10. Mastering Vue 3 - Part 10 [Animation in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-53gh"&gt;11. Mastering Vue 3 - Part 11 [State Management with Pinia]&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;12. Mastering Vue 3 - Part 12 [Teleport in vue 3]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3m94"&gt;13. Mastering Vue 3 - Part 13 [Working with API Calls ]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4bhi"&gt;14. Mastering Vue 3 - Part 14 [Forms and Form Validation ]&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Teleport in vue 3
&lt;/h1&gt;

&lt;p&gt;Teleport is a feature introduced in Vue 3 that allows you to render a component's content in a different part of the DOM, outside of its parent component. It enables you to create more flexible and dynamic UIs by rendering content in different DOM locations without losing the component's state or re-rendering the entire component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using Teleport:
&lt;/h3&gt;

&lt;p&gt;To use Teleport in Vue 3, you need to wrap the content you want to teleport with the &lt;code&gt;&amp;lt;teleport&amp;gt;&lt;/code&gt; element. The &lt;code&gt;&amp;lt;teleport&amp;gt;&lt;/code&gt; element takes a &lt;code&gt;to&lt;/code&gt; attribute that specifies the target destination for the teleported content. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"toggleModal"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Open Modal&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;teleport&lt;/span&gt; &lt;span class="na"&gt;to=&lt;/span&gt;&lt;span class="s"&gt;"body"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;Modal&lt;/span&gt; &lt;span class="na"&gt;v-if=&lt;/span&gt;&lt;span class="s"&gt;"isModalOpen"&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;close=&lt;/span&gt;&lt;span class="s"&gt;"toggleModal"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/teleport&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, when the "Open Modal" button is clicked, the &lt;code&gt;Modal&lt;/code&gt; component is rendered and teleported to the &lt;code&gt;body&lt;/code&gt; element. The &lt;code&gt;Modal&lt;/code&gt; component is defined elsewhere in the code and emits a &lt;code&gt;close&lt;/code&gt; event when the user interacts with it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Teleporting Modals and Dialogs:
&lt;/h3&gt;

&lt;p&gt;One common use case for Teleport is rendering modals and dialogs. By teleporting the modal content to the &lt;code&gt;body&lt;/code&gt; element, you can ensure that it overlays other content and is not constrained by its parent component's layout. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"openModal"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Open Modal&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;teleport&lt;/span&gt; &lt;span class="na"&gt;to=&lt;/span&gt;&lt;span class="s"&gt;"body"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;Modal&lt;/span&gt; &lt;span class="na"&gt;v-if=&lt;/span&gt;&lt;span class="s"&gt;"isModalOpen"&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;close=&lt;/span&gt;&lt;span class="s"&gt;"closeModal"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/teleport&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;Modal&lt;/code&gt; component is teleported to the &lt;code&gt;body&lt;/code&gt; element when the &lt;code&gt;isModalOpen&lt;/code&gt; data property is true. The &lt;code&gt;Modal&lt;/code&gt; component emits a &lt;code&gt;close&lt;/code&gt; event when the user interacts with it, triggering the &lt;code&gt;closeModal&lt;/code&gt; method to update the &lt;code&gt;isModalOpen&lt;/code&gt; data property.&lt;/p&gt;

&lt;h3&gt;
  
  
  Teleporting Content to Portals:
&lt;/h3&gt;

&lt;p&gt;Another use case for Teleport is creating portal-like behavior in Vue 3 applications. You can render content in a dedicated portal container, which can be useful for scenarios like creating tooltips, dropdown menus, or custom overlays. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"toggleDropdown"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Toggle Dropdown&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;teleport&lt;/span&gt; &lt;span class="na"&gt;to=&lt;/span&gt;&lt;span class="s"&gt;"#dropdown-container"&lt;/span&gt; &lt;span class="na"&gt;v-if=&lt;/span&gt;&lt;span class="s"&gt;"isDropdownOpen"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;DropdownMenu&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/teleport&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"dropdown-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, when the "Toggle Dropdown" button is clicked, the &lt;code&gt;DropdownMenu&lt;/code&gt; component is rendered and teleported to the &lt;code&gt;#dropdown-container&lt;/code&gt; element, which is a dedicated container outside of the component's hierarchy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Server-Side Rendering (SSR) Considerations:
&lt;/h3&gt;

&lt;p&gt;When using Teleport in server-side rendered Vue 3 applications, you need to handle the differences between client-side and server-side rendering. During SSR, the teleported content will be rendered at its original position, and on the client-side, it will be teleported to the desired destination. Ensure proper rendering and rehydration of teleported content during SSR by using conditional rendering or dynamic imports.&lt;/p&gt;

&lt;h3&gt;
  
  
  Teleport and Transition/Animation:
&lt;/h3&gt;

&lt;p&gt;You can combine Teleport with Vue 3's transition and animation features to apply transitions or animations to teleported content. By wrapping the teleported content with a &lt;code&gt;&amp;lt;transition&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;transition-group&amp;gt;&lt;/code&gt; element, you can add visual effects when the content is teleported to another DOM location. Refer to Vue's transition and animation documentation for more details on incorporating these features with Teleport.&lt;/p&gt;

&lt;h3&gt;
  
  
  Caveats and Limitations:
&lt;/h3&gt;

&lt;p&gt;When using Teleport in Vue 3, there are a few caveats and limitations to be aware of. For example, nested teleports may not work as expected, and you should avoid teleporting content inside elements with CSS properties like &lt;code&gt;transform&lt;/code&gt; or &lt;code&gt;will-change&lt;/code&gt; that can interfere with the rendering. Additionally, certain browser features, like the Shadow DOM, may affect the behavior of Teleport. Refer to the Vue documentation for a comprehensive list of limitations and known issues.&lt;/p&gt;

&lt;h3&gt;
  
  
  Best Practices:
&lt;/h3&gt;

&lt;p&gt;Consider the following best practices when using Teleport in Vue 3 applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Teleport sparingly and only when necessary. In most cases, the default Vue component rendering behavior will suffice.&lt;/li&gt;
&lt;li&gt;Clearly define the target destination for teleported content to ensure it is placed in the desired location.&lt;/li&gt;
&lt;li&gt;Test and verify the behavior of teleported components, especially when it comes to event handling and component lifecycle.&lt;/li&gt;
&lt;li&gt;Document the usage of Teleport in your codebase to make it clear where and why it is being used.&lt;/li&gt;
&lt;li&gt;Follow Vue's recommended practices for component design and separation of concerns, even when using Teleport.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By understanding the usage, considerations, and limitations of Teleport in Vue 3, you can effectively leverage this feature to create more flexible and dynamic user interfaces in your applications.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>vue</category>
    </item>
    <item>
      <title>Mastering Vue 3: A Comprehensive Guide to Building Modern Web Applications &lt;Part 11 /&gt;</title>
      <dc:creator>Hany Taha</dc:creator>
      <pubDate>Mon, 26 Feb 2024 22:17:20 +0000</pubDate>
      <link>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-53gh</link>
      <guid>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-53gh</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Content:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-1--c75"&gt;Mastering Vue 3 - Part 1 [Introduction and key features]&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-2--1k0l"&gt;2. Mastering Vue 3 - Part 2 [Benefits of using Vue 3 for web development]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-3--fde"&gt;3. Mastering Vue 3 - Part 3 [Template syntax in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-19c0"&gt;4. Mastering Vue 3 - Part 4 [Reactivity Fundamentals]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-16g"&gt;5. Mastering Vue 3 - Part 5 [Class and Style Bindings]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-1c6e"&gt;6. Mastering Vue 3 - Part 6 [Lifecycle Hooks]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3nnd"&gt;7. Mastering Vue 3 - Part 7 [Understanding components]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-17ge"&gt;8. Mastering Vue 3 - Part 8 [Installing Vue project and file structure]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5d1p"&gt;9. Mastering Vue 3 - Part 9 [Vue Router in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4ig2"&gt;10. Mastering Vue 3 - Part 10 [Animation in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;11. Mastering Vue 3 - Part 11 [State Management with Pinia]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;12. Mastering Vue 3 - Part 12 [Teleport in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;13. Mastering Vue 3 - Part 13 [Working with API Calls ]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4bhi"&gt;14. Mastering Vue 3 - Part 14 [Forms and Form Validation ]&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  State Management with Pinia
&lt;/h2&gt;

&lt;p&gt;State management plays a crucial role in Vue 3 applications, especially when dealing with complex and shared data across multiple components. It helps in maintaining a single source of truth for the application's data, making it easier to manage and update.&lt;/p&gt;

&lt;p&gt;One popular state management solution for Vue 3 is Pinia. Pinia is a modern and lightweight state management library specifically built for Vue 3 applications. It provides a centralized store pattern, similar to Vuex in Vue 2, but with enhanced TypeScript support and improved performance.&lt;/p&gt;

&lt;p&gt;Using Pinia for Centralized State Management:&lt;br&gt;
To use Pinia for centralized state management in your Vue 3 application, follow these steps:&lt;/p&gt;

&lt;p&gt;1- Install Pinia: Start by installing Pinia via npm or yarn:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;pinia
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2- Create a Store: Create a new store file, for example &lt;code&gt;store.js&lt;/code&gt;, and import Pinia:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createPinia&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pinia&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pinia&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createPinia&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3- Register the Store: In your main application file, import the Pinia instance and register the store:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createApp&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;pinia&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./store.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pinia&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4- Define State, Actions, and Getters: In your store file, define the state, actions, and getters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;defineStore&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pinia&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useCounterStore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;defineStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;counter&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="p"&gt;}),&lt;/span&gt;

  &lt;span class="na"&gt;getters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;doubleCount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;

  &lt;span class="na"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we create a store called &lt;code&gt;counter&lt;/code&gt; using &lt;code&gt;defineStore()&lt;/code&gt;. The store includes a &lt;code&gt;state&lt;/code&gt; object with a &lt;code&gt;count&lt;/code&gt; property. It also defines a getter called &lt;code&gt;doubleCount&lt;/code&gt;, which returns the double of the &lt;code&gt;count&lt;/code&gt; value, and an action called &lt;code&gt;increment&lt;/code&gt; that increments the &lt;code&gt;count&lt;/code&gt; value.&lt;/p&gt;

&lt;p&gt;5- Access the Store in Components: To use the store in your components, import it and access the state, actions, or getters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Count: &lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Double Count: &lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;doubleCount&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"counter.increment()"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Increment&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useCounterStore&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./store.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCounterStore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we import the &lt;code&gt;useCounterStore&lt;/code&gt; function from the store file and call it in the &lt;code&gt;setup()&lt;/code&gt; function. This provides us with access to the &lt;code&gt;counter&lt;/code&gt; store instance, which we can use in the template and methods.&lt;/p&gt;

&lt;p&gt;Organizing State, Actions, and Getters in Pinia:&lt;br&gt;
In Pinia, you can organize your state, actions, and getters within a store. This helps in maintaining a clear structure and separation of concerns. You can define them using the &lt;code&gt;state&lt;/code&gt;, &lt;code&gt;actions&lt;/code&gt;, and &lt;code&gt;getters&lt;/code&gt; properties in the store definition.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;State&lt;/strong&gt;: The state represents the data managed by the store. It can be defined as a function that returns an object containing the initial state values.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Actions&lt;/strong&gt;: Actions are the equivalent of methods in components. They can be defined with the actions property in defineStore() and they are perfect to define business logic.&lt;br&gt;
Like getters, actions get access to the whole store instance through this with full typing (and autocompletion ✨) support. Unlike getters, actions can be asynchronous, you can await inside of actions any API call or even other actions!. Note the library you use doesn't matter as long as you get a Promise, you could even use the native fetch function (browser only)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Getters&lt;/strong&gt;: Getters provide computed properties based on the state. They can be used to derive values from the state or perform calculations. Getters are defined within the &lt;code&gt;getters&lt;/code&gt; property of the store.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By organizing your state, actions, and getters in separate sections, you can maintain a clear structure and easily understand and manage your application's data flow.&lt;/p&gt;

&lt;p&gt;Pinia provides a simple and intuitive API for state management in Vue 3 applications. It promotes a centralized store pattern, making it easier to share and manage data across components. With TypeScript support and improved performance, Pinia is a robust choice for state management in Vue 3.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>vue</category>
    </item>
    <item>
      <title>Mastering Vue 3: A Comprehensive Guide to Building Modern Web Applications &lt;Part 10 /&gt;</title>
      <dc:creator>Hany Taha</dc:creator>
      <pubDate>Sun, 18 Feb 2024 19:25:06 +0000</pubDate>
      <link>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4ig2</link>
      <guid>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4ig2</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Content:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-1--c75"&gt;Mastering Vue 3 - Part 1 [Introduction and key features]&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-2--1k0l"&gt;2. Mastering Vue 3 - Part 2 [Benefits of using Vue 3 for web development]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-3--fde"&gt;3. Mastering Vue 3 - Part 3 [Template syntax in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-19c0"&gt;4. Mastering Vue 3 - Part 4 [Reactivity Fundamentals]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-16g"&gt;5. Mastering Vue 3 - Part 5 [Class and Style Bindings]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-1c6e"&gt;6. Mastering Vue 3 - Part 6 [Lifecycle Hooks]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3nnd"&gt;7. Mastering Vue 3 - Part 7 [Understanding components]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-17ge"&gt;8. Mastering Vue 3 - Part 8 [Installing Vue project and file structure]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5d1p"&gt;9. Mastering Vue 3 - Part 9 [Vue Router in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10. Mastering Vue 3 - Part 10 [Animation in Vue 3]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-53gh"&gt;11. Mastering Vue 3 - Part 11 [State Management with Pinia]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;12. Mastering Vue 3 - Part 12 [Teleport in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;13. Mastering Vue 3 - Part 13 [Working with API Calls ]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4bhi"&gt;14. Mastering Vue 3 - Part 14 [Forms and Form Validation ]&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Animation in Vue 3
&lt;/h2&gt;

&lt;p&gt;In Vue 3, you can add animations to your application using the built-in transition system called "Transition" and the "TransitionGroup" component. These features allow you to apply various animations when elements are added, updated, or removed from the DOM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1- Adding Animations with Transition:&lt;/strong&gt;&lt;br&gt;
The "Transition" component is used to animate elements when they are added, updated, or removed from the DOM. Here's an example of how to use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;transition&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"fade"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;v-if=&lt;/span&gt;&lt;span class="s"&gt;"show"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"box"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/transition&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the "fade" class will be added to the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; element when it is inserted or removed from the DOM. You can define the animation styles for the "fade" class in your CSS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2- Defining Transition Styles:&lt;/strong&gt;&lt;br&gt;
To define the animation styles for the transition classes, you can use CSS or CSS frameworks like Tailwind CSS or Bootstrap. Here's an example of how to define a fade animation using CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.fade-enter-active&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nc"&gt;.fade-leave-active&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;opacity&lt;/span&gt; &lt;span class="m"&gt;0.5s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.fade-enter-from&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nc"&gt;.fade-leave-to&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the "fade-enter-active" and "fade-leave-active" classes define the transition properties, while the "fade-enter-from" and "fade-leave-to" classes define the initial and final states of the animation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3- Adding Transition Modes:&lt;/strong&gt;&lt;br&gt;
The "Transition" component supports different modes that determine how elements are animated. The available modes are "in-out", "out-in", and the default mode. Here's an example of using the "in-out" mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;transition&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"fade"&lt;/span&gt; &lt;span class="na"&gt;mode=&lt;/span&gt;&lt;span class="s"&gt;"out-in"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;v-if=&lt;/span&gt;&lt;span class="s"&gt;"show"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"box"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/transition&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the "mode" attribute is set to "out-in", which means that the current element will animate out first, and then the new element will animate in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4- Using Transition Events:&lt;/strong&gt;&lt;br&gt;
The "Transition" component provides several events that you can use to trigger actions during the animation lifecycle. The available events are "before-enter", "enter", "after-enter", "before-leave", "leave", and "after-leave". Here's an example of using the "enter" event:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;transition&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"fade"&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;enter=&lt;/span&gt;&lt;span class="s"&gt;"onEnter"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;v-if=&lt;/span&gt;&lt;span class="s"&gt;"show"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"box"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/transition&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the "onEnter" method will be called when the element enters the DOM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5- Animating Lists with TransitionGroup:&lt;/strong&gt;&lt;br&gt;
The "TransitionGroup" component is used to animate lists of items. It works similarly to the "Transition" component but applies the animations to each item in the list. Here's an example of using "TransitionGroup":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;transition-group&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"list"&lt;/span&gt; &lt;span class="na"&gt;tag=&lt;/span&gt;&lt;span class="s"&gt;"ul"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;v-for=&lt;/span&gt;&lt;span class="s"&gt;"item in items"&lt;/span&gt; &lt;span class="na"&gt;:key=&lt;/span&gt;&lt;span class="s"&gt;"item.id"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"list-item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;{{ item.text }}&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/transition-group&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the "list" class will be applied to each list item when they are added, updated, or removed from the list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;br&gt;
Vue 3 provides a powerful transition system that allows you to add animations to your application with ease. By using the "Transition" component and the "TransitionGroup" component, you can apply animations to individual elements or lists. You can define the animation styles using CSS and utilize the available transition modes and events to create dynamic and engaging user experiences. Experiment with different animations and explore the Vue 3 documentation for more advanced animation techniques and options. Happy animating!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>vue</category>
    </item>
    <item>
      <title>Mastering Vue 3: A Comprehensive Guide to Building Modern Web Applications &lt;Part 9 /&gt;</title>
      <dc:creator>Hany Taha</dc:creator>
      <pubDate>Mon, 12 Feb 2024 20:22:45 +0000</pubDate>
      <link>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5d1p</link>
      <guid>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5d1p</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Content:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-1--c75"&gt;Mastering Vue 3 - Part 1 [Introduction and key features]&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-2--1k0l"&gt;2. Mastering Vue 3 - Part 2 [Benefits of using Vue 3 for web development]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-3--fde"&gt;3. Mastering Vue 3 - Part 3 [Template syntax in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-19c0"&gt;4. Mastering Vue 3 - Part 4 [Reactivity Fundamentals]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-16g"&gt;5. Mastering Vue 3 - Part 5 [Class and Style Bindings]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-1c6e"&gt;6. Mastering Vue 3 - Part 6 [Lifecycle Hooks]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3nnd"&gt;7. Mastering Vue 3 - Part 7 [Understanding components]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-17ge"&gt;8. Mastering Vue 3 - Part 8 [Installing Vue project and file structure]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. Mastering Vue 3 - Part 9 [Vue Router in Vue 3]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4ig2"&gt;10. Mastering Vue 3 - Part 10 [Animation in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-53gh"&gt;11. Mastering Vue 3 - Part 11 [State Management with Pinia]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;12. Mastering Vue 3 - Part 12 [Teleport in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;13. Mastering Vue 3 - Part 13 [Working with API Calls ]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4bhi"&gt;14. Mastering Vue 3 - Part 14 [Forms and Form Validation ]&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Vue Router in Vue 3
&lt;/h2&gt;

&lt;p&gt;Vue Router is a powerful routing library for Vue.js applications that allows you to build single-page applications (SPAs) with multiple views. It provides a seamless navigation experience by organizing your application into different routes, each representing a unique URL. In this blog post, we will explore the fundamentals of Vue Router in Vue 3 and provide examples, including nested routes, to help you understand its usage and capabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;(1) Getting Started with Vue Router&lt;/strong&gt;:&lt;br&gt;
To begin, you need to install Vue Router into your Vue 3 project. Open your terminal and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;vue-router@next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, import Vue Router into your main.js file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createApp&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createRouter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;createWebHistory&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-router&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createRouter&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;history&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;createWebHistory&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;routes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="c1"&gt;// Define your routes here&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;(2) Defining Routes&lt;/strong&gt;:&lt;br&gt;
Routes are the building blocks of Vue Router. Each route represents a unique URL and maps to a specific component. Let's take a look at an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Home&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/Home.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;About&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/About.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;routes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Home&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/about&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;About&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;About&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have two routes: the root route ("/") mapped to the Home component and the "/about" route mapped to the About component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;(3) Rendering Views&lt;/strong&gt;:&lt;br&gt;
To display the appropriate component for each route, we need to render the &lt;code&gt;&amp;lt;router-view&amp;gt;&lt;/code&gt; component in the template of our main App.vue file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;router-view&amp;gt;&amp;lt;/router-view&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;&amp;lt;router-view&amp;gt;&lt;/code&gt; component acts as a placeholder that Vue Router will replace with the component associated with the current route.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;(4) Navigating Between Routes&lt;/strong&gt;:&lt;br&gt;
Vue Router provides a &lt;code&gt;&amp;lt;router-link&amp;gt;&lt;/code&gt; component to create links for navigation. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;router-link&lt;/span&gt; &lt;span class="na"&gt;to=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/router-link&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;router-link&lt;/span&gt; &lt;span class="na"&gt;to=&lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;About&lt;span class="nt"&gt;&amp;lt;/router-link&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clicking on these links will navigate the user to the respective routes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;(5) Nested Routes&lt;/strong&gt;:&lt;br&gt;
Vue Router also supports nested routes, allowing you to create hierarchical navigation structures. To define nested routes, you can include a &lt;code&gt;children&lt;/code&gt; property within a route configuration object. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Dashboard&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/Dashboard.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Profile&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/Profile.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Settings&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/Settings.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;routes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/dashboard&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Dashboard&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;profile&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Profile&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;settings&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Settings&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the "/dashboard" route is associated with the Dashboard component, and it contains two child routes: "/dashboard/profile" and "/dashboard/settings".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;(6) Accessing Route Parameters&lt;/strong&gt;:&lt;br&gt;
In many cases, you might need to pass parameters to your routes. Vue Router allows you to define dynamic segments in your route paths and access them in your components. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;routes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/user/:id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;User&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the User component, you can access the &lt;code&gt;id&lt;/code&gt; parameter through &lt;code&gt;this.$route.params.id&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;(7) Programmatic Navigation&lt;/strong&gt;:&lt;br&gt;
You can also navigate programmatically using the &lt;code&gt;router.push()&lt;/code&gt; method. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/about&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code will navigate the user to the "/about" route.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;:&lt;br&gt;
Vue Router is an essential tool for building SPAs in Vue 3. By defining routes, rendering views, and navigating between them, you can create a seamless and interactive user experience. Nested routes provide a way to create hierarchical navigation structures within your application. In this blog post, we covered the basics of Vue Router, including nested routes, and provided examples to help you get started. With this knowledge, you can take your Vue 3 projects to the next level by implementing routing capabilities.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>vue</category>
    </item>
    <item>
      <title>Mastering Vue 3: A Comprehensive Guide to Building Modern Web Applications &lt;Part 8 /&gt;</title>
      <dc:creator>Hany Taha</dc:creator>
      <pubDate>Fri, 09 Feb 2024 12:05:33 +0000</pubDate>
      <link>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-17ge</link>
      <guid>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-17ge</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Content:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-1--c75"&gt;Mastering Vue 3 - Part 1 [Introduction and key features]&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-2--1k0l"&gt;2. Mastering Vue 3 - Part 2 [Benefits of using Vue 3 for web development]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-3--fde"&gt;3. Mastering Vue 3 - Part 3 [Template syntax in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-19c0"&gt;4. Mastering Vue 3 - Part 4 [Reactivity Fundamentals]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-16g"&gt;5. Mastering Vue 3 - Part 5 [Class and Style Bindings]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-1c6e"&gt;6. Mastering Vue 3 - Part 6 [Lifecycle Hooks]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3nnd"&gt;7. Mastering Vue 3 - Part 7 [Understanding components]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Mastering Vue 3 - Part 8 [Installing Vue project and file structure]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5d1p"&gt;9. Mastering Vue 3 - Part 9 [Vue Router in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4ig2"&gt;10. Mastering Vue 3 - Part 10 [Animation in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-53gh"&gt;11. Mastering Vue 3 - Part 11 [State Management with Pinia]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;12. Mastering Vue 3 - Part 12 [Teleport in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;13. Mastering Vue 3 - Part 13 [Working with API Calls ]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4bhi"&gt;14. Mastering Vue 3 - Part 14 [Forms and Form Validation ]&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Installing Vue project and file structure
&lt;/h1&gt;

&lt;h4&gt;
  
  
  (1) Setting Up a Vue 3 Project Using npm and Vite
&lt;/h4&gt;

&lt;p&gt;Vue 3, the latest iteration of the popular JavaScript framework, has garnered attention for its enhanced reactivity system and the Composition API. When combined with Vite, a build tool that prioritizes speed and efficiency, Vue 3 becomes an even more compelling choice for modern web development. In this blog post, we will provide a comprehensive guide to setting up a Vue 3 project using npm and Vite, empowering developers to kickstart their Vue 3 journey with confidence.  &lt;/p&gt;

&lt;h4&gt;
  
  
  (2) Prerequisites
&lt;/h4&gt;

&lt;p&gt;Before diving into the project setup, ensure that Node.js and npm are installed on your system. These tools are essential for managing dependencies and running scripts within your Vue 3 project. Once you have Node.js and npm installed, you are ready to embark on the journey of setting up your Vue 3 project.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Creating a New Vue 3 Project
&lt;/h3&gt;

&lt;p&gt;To create a new Vue 3 project, open your code editor (I use VS Code) then open the built-in terminal and run the following command:&lt;br&gt;
&lt;br&gt;
  &lt;code&gt;npm init vite&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
  Choose project name then choose vue as a framework then Javascript as a variant.&lt;br&gt;
This command initializes a new Vue 3 project using Vite as the build tool, setting up the necessary project structure and dependencies.  &lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2: Navigating to the Project Directory
&lt;/h3&gt;

&lt;p&gt;Once the project has been created, navigate to the project directory using the following command:&lt;br&gt;
&lt;br&gt;
  &lt;code&gt;cd &amp;lt;project name&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
  This command will take you to the root directory of your newly created Vue 3 project.  &lt;/p&gt;
&lt;h3&gt;
  
  
  Step 3: Installing Dependencies
&lt;/h3&gt;

&lt;p&gt;Next, install the project dependencies using npm. Run the following command in your terminal:&lt;br&gt;
&lt;br&gt;
  &lt;code&gt;npm install&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This command will fetch and install all the required dependencies specified in the project's &lt;code&gt;package.json&lt;/code&gt; file.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Running the Development Server
&lt;/h3&gt;

&lt;p&gt;To start the development server and begin working on your Vue 3 project, run the following command:&lt;br&gt;
&lt;br&gt;
  &lt;code&gt;npm run dev&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This command initiates the Vite development server, providing a fast and efficient development environment for your Vue 3 application.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Building for Production
&lt;/h3&gt;

&lt;p&gt;When you are ready to build your Vue 3 project for production, run the following command:&lt;br&gt;
&lt;br&gt;
  &lt;code&gt;npm run build&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This command triggers the production build process, generating optimized bundles for deployment. &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: Launching the Production Server
&lt;/h3&gt;

&lt;p&gt;To preview the production build locally, run the following command:&lt;br&gt;
&lt;br&gt;
  &lt;code&gt;npm run serve&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
  This command serves the production build of your Vue 3 project, allowing you to preview the optimized application locally before deployment.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Exploring the project structure and key files
&lt;/h2&gt;

&lt;p&gt;Vue 3, renowned for its reactivity system and the Composition API, offers a well-defined project structure that facilitates organized and scalable development. In this section, we will explore the Vue 3 project structure and delve into the key files that form the foundation of a Vue 3 application, empowering developers to gain a comprehensive understanding of their Vue 3 projects.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Project Structure Overview
&lt;/h3&gt;

&lt;p&gt;Upon creating a new Vue 3 project, developers are presented with a well-organized directory structure that fosters clarity, maintainability, and scalability. Let's take a closer look at the key directories and files within a typical Vue 3 project:  &lt;/p&gt;

&lt;h4&gt;
  
  
  The &lt;code&gt;src&lt;/code&gt; Directory
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;src&lt;/code&gt; directory serves as the heart of a Vue 3 project, housing the source code and essential files that constitute the application. &lt;br&gt;
Within the &lt;code&gt;src&lt;/code&gt; directory, developers will encounter the following key files and subdirectories:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;main.js&lt;/code&gt;&lt;/strong&gt;: This file acts as the entry point of the Vue 3 application, where the Vue instance is created and the root component is mounted to the DOM. It serves as a pivotal file in the project structure, orchestrating the initialization of the Vue 3 application.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;App.vue&lt;/code&gt;&lt;/strong&gt;: As the root component of the application, &lt;code&gt;App.vue&lt;/code&gt; encapsulates the overarching layout and structure of the user interface. It typically consists of the template, script, and style sections, embodying the essence of the application's visual and interactive components.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;components&lt;/code&gt; Directory&lt;/strong&gt;: The &lt;code&gt;components&lt;/code&gt; directory houses reusable and modular Vue components that contribute to the building blocks of the application. Organizing components in this dedicated directory promotes code reusability, maintainability, and a structured approach to component-based development.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;assets&lt;/code&gt; Directory&lt;/strong&gt;: Within the &lt;code&gt;assets&lt;/code&gt; directory, developers can store static assets such as images, fonts, and stylesheets that are utilized across the application. This directory ensures a cohesive and organized approach to managing project assets.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;views&lt;/code&gt; Directory&lt;/strong&gt;: The &lt;code&gt;views&lt;/code&gt; directory contains Vue components that represent distinct pages or views within the application. By organizing views separately, developers can maintain a clear separation of concerns and facilitate streamlined navigation within the project.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;router&lt;/code&gt; Directory (if using Vue Router)&lt;/strong&gt;: When incorporating Vue Router for client-side routing, the &lt;code&gt;router&lt;/code&gt; directory hosts the routing configuration and related files, enabling developers to define and manage the application's navigation logic in a centralized manner.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;store&lt;/code&gt; Directory (if using Vuex/pinia)&lt;/strong&gt;: If Vuex/pinia is employed for state management, the &lt;code&gt;store&lt;/code&gt; directory accommodates the state management logic, including modules, actions, mutations, and getters, that collectively govern the application's global state.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Additional Configuration Files
&lt;/h4&gt;

&lt;p&gt;In addition to the &lt;code&gt;src&lt;/code&gt; directory, Vue 3 projects typically encompass various configuration files that influence the behavior and settings of the application. &lt;br&gt;
Notable configuration files include:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;package.json&lt;/code&gt;&lt;/strong&gt;: The &lt;code&gt;package.json&lt;/code&gt; file contains metadata about the project, as well as the dependencies, scripts, and configuration settings essential for managing the project's development, dependencies, and build processes.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;vite.config.js&lt;/code&gt;&lt;/strong&gt;: When utilizing Vite as the build tool, the &lt;code&gt;vite.config.js&lt;/code&gt; file houses the configuration for the Vite build system, allowing developers to customize the project's build process, asset handling, and development server settings.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Additional Configuration Files&lt;/strong&gt;: Depending on the specific requirements of the project, developers may encounter additional configuration files such as &lt;code&gt;.eslintrc&lt;/code&gt;, &lt;code&gt;babel.config.js&lt;/code&gt;, or &lt;code&gt;.editorconfig&lt;/code&gt; that contribute to the overall project configuration and development workflow.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;By following these steps, you have successfully set up a Vue 3 project using npm and Vite. With a robust development environment and efficient build process at your disposal, you are well-equipped to embark on your Vue 3 development journey with confidence, leveraging the enhanced reactivity system and the innovative Composition API offered by Vue 3. The Vue 3 project structure and key files provide a robust foundation for building modern and responsive web applications. By gaining a comprehensive understanding of the project structure and the purpose of key files, developers can streamline development, promote code maintainability, and leverage the full potential of Vue 3's capabilities.&lt;br&gt;
--- In this part, I provided a step-by-step guide to setting up a Vue 3 project using npm and Vite. I also provided a comprehensive overview of the Vue 3 project structure and key files, empowering developers to gain a deep understanding of their Vue 3 projects and to kickstart their Vue 3 journey with confidence. If you need further details on any aspect, feel free to ask!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>vue</category>
    </item>
    <item>
      <title>Mastering Vue 3: A Comprehensive Guide to Building Modern Web Applications &lt;Part 7 /&gt;</title>
      <dc:creator>Hany Taha</dc:creator>
      <pubDate>Sun, 04 Feb 2024 22:59:44 +0000</pubDate>
      <link>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3nnd</link>
      <guid>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3nnd</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Content:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-1--c75"&gt;Mastering Vue 3 - Part 1 [Introduction and key features]&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-2--1k0l"&gt;2. Mastering Vue 3 - Part 2 [Benefits of using Vue 3 for web development]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-3--fde"&gt;3. Mastering Vue 3 - Part 3 [Template syntax in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-19c0"&gt;4. Mastering Vue 3 - Part 4 [Reactivity Fundamentals]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-16g"&gt;5. Mastering Vue 3 - Part 5 [Class and Style Bindings]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-1c6e"&gt;6. Mastering Vue 3 - Part 6 [Lifecycle Hooks]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Mastering Vue 3 - Part 7 [Understanding components]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-17ge"&gt;8. Mastering Vue 3 - Part 8 [Installing Vue project and file structure]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5d1p"&gt;9. Mastering Vue 3 - Part 9 [Vue Router in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4ig2"&gt;10. Mastering Vue 3 - Part 10 [Animation in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-53gh"&gt;11. Mastering Vue 3 - Part 11 [State Management with Pinia]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;12. Mastering Vue 3 - Part 12 [Teleport in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;13. Mastering Vue 3 - Part 13 [Working with API Calls ]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4bhi"&gt;14. Mastering Vue 3 - Part 14 [Forms and Form Validation ]&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Understanding components in Vue 3
&lt;/h2&gt;

&lt;p&gt;Components in Vue 3 are reusable and self-contained units of UI that encapsulate the HTML, CSS, and JavaScript logic required to render a specific part of a user interface. They promote modularization, code reusability, and easier maintenance by breaking down complex UIs into smaller, manageable pieces.&lt;br&gt;
**Here are some key points about components in Vue 3:&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Component Structure:
&lt;/h3&gt;

&lt;p&gt;A Vue 3 component consists of three parts: template, script, and style.&lt;br&gt;
1- &lt;strong&gt;The template&lt;/strong&gt; contains the HTML structure and defines the component's markup.&lt;br&gt;
2- &lt;strong&gt;The script&lt;/strong&gt; section contains the JavaScript logic for the component, including data properties, methods, computed properties, and lifecycle hooks.&lt;br&gt;
3- &lt;strong&gt;The style&lt;/strong&gt; section contains CSS styles specific to the component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;     &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

     &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, Vue 3!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="p"&gt;};&lt;/span&gt;
       &lt;span class="p"&gt;},&lt;/span&gt;
     &lt;span class="p"&gt;};&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

     &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;style&lt;/span&gt; &lt;span class="na"&gt;scoped&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;style&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; In this example, the component has a simple structure. The template contains an &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; element that displays the &lt;code&gt;message&lt;/code&gt; data property. The script section defines the &lt;code&gt;data&lt;/code&gt; property with an initial value of &lt;code&gt;'Hello, Vue 3!'&lt;/code&gt;. The style section contains a scoped style that makes the text color of the &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; element blue.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Component Composition:
&lt;/h3&gt;

&lt;p&gt;Components can be composed hierarchically, allowing for the creation of complex UIs from smaller, reusable components.&lt;br&gt;
Parent components can include child components by using custom HTML tags.&lt;br&gt;
Components can pass data to child components using props and receive data back using events.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;ChildComponent&lt;/span&gt; &lt;span class="na"&gt;:name=&lt;/span&gt;&lt;span class="s"&gt;"user.name"&lt;/span&gt; &lt;span class="na"&gt;:age=&lt;/span&gt;&lt;span class="s"&gt;"user.age"&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;updateAge=&lt;/span&gt;&lt;span class="s"&gt;"updateAge"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

     &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ChildComponent&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./ChildComponent.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

     &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="na"&gt;components&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nx"&gt;ChildComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="p"&gt;},&lt;/span&gt;
       &lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="p"&gt;},&lt;/span&gt;
         &lt;span class="p"&gt;};&lt;/span&gt;
       &lt;span class="p"&gt;},&lt;/span&gt;
       &lt;span class="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nf"&gt;updateAge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newAge&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newAge&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
         &lt;span class="p"&gt;},&lt;/span&gt;
       &lt;span class="p"&gt;},&lt;/span&gt;
     &lt;span class="p"&gt;};&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; In this example, the parent component (&lt;code&gt;ParentComponent&lt;/code&gt;) includes the child component (&lt;code&gt;ChildComponent&lt;/code&gt;) using the custom HTML tag &lt;code&gt;&amp;lt;ChildComponent&amp;gt;&lt;/code&gt;. The parent component passes the &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;age&lt;/code&gt; props to the child component, and listens to the &lt;code&gt;updateAge&lt;/code&gt; event emitted by the child component. When the event is emitted, the parent component's &lt;code&gt;updateAge&lt;/code&gt; method is called to update the &lt;code&gt;age&lt;/code&gt; property.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Data and Props:
&lt;/h3&gt;

&lt;p&gt;Each component can have its own data properties, which are reactive and can be accessed in the template and script sections.&lt;br&gt;
Props are used to pass data from parent components to child components.&lt;br&gt;
Props are declared in the component's script section and can be type-checked for improved code reliability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;ChildComponent&lt;/span&gt; &lt;span class="na"&gt;:name=&lt;/span&gt;&lt;span class="s"&gt;"user.name"&lt;/span&gt; &lt;span class="na"&gt;:age=&lt;/span&gt;&lt;span class="s"&gt;"user.age"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

     &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ChildComponent&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./ChildComponent.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

     &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="na"&gt;components&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nx"&gt;ChildComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="p"&gt;},&lt;/span&gt;
       &lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, Vue 3!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="p"&gt;},&lt;/span&gt;
         &lt;span class="p"&gt;};&lt;/span&gt;
       &lt;span class="p"&gt;},&lt;/span&gt;
     &lt;span class="p"&gt;};&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; In this example, the parent component has a &lt;code&gt;message&lt;/code&gt; data property and a &lt;code&gt;user&lt;/code&gt; data property. The &lt;code&gt;message&lt;/code&gt; property is displayed in the parent component's template, and the &lt;code&gt;user&lt;/code&gt; object is passed as props to the child component (&lt;code&gt;ChildComponent&lt;/code&gt;) using the &lt;code&gt;:name&lt;/code&gt; and &lt;code&gt;:age&lt;/code&gt; syntax.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Component Lifecycle Hooks:
&lt;/h3&gt;

&lt;p&gt;Vue 3 provides a set of lifecycle hooks that allow you to execute code at specific stages of a component's lifecycle.&lt;br&gt;
Common lifecycle hooks include created, mounted, updated, and beforeUnmount.&lt;br&gt;
Lifecycle hooks provide opportunities to perform tasks such as fetching data, setting up event listeners, or cleaning up resources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;     &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

     &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, Vue 3!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="p"&gt;};&lt;/span&gt;
       &lt;span class="p"&gt;},&lt;/span&gt;
       &lt;span class="nf"&gt;created&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Component created&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
       &lt;span class="p"&gt;},&lt;/span&gt;
       &lt;span class="nf"&gt;mounted&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Component mounted&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
       &lt;span class="p"&gt;},&lt;/span&gt;
       &lt;span class="nf"&gt;updated&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Component updated&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
       &lt;span class="p"&gt;},&lt;/span&gt;
       &lt;span class="nf"&gt;beforeUnmount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Component before unmount&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
       &lt;span class="p"&gt;},&lt;/span&gt;
     &lt;span class="p"&gt;};&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; In this example, the component includes lifecycle hooks such as &lt;code&gt;created&lt;/code&gt;, &lt;code&gt;mounted&lt;/code&gt;, &lt;code&gt;updated&lt;/code&gt;, and &lt;code&gt;beforeUnmount&lt;/code&gt;. Each hook represents a specific stage in the component's lifecycle. When the component is created, mounted, updated, or about to be unmounted, the corresponding hook is triggered, and the associated console log is executed.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Component Communication:
&lt;/h3&gt;

&lt;p&gt;Components can communicate with each other through props and events.&lt;br&gt;
Props allow parent components to pass data down to child components, while events enable child components to emit events that the parent components can listen to and respond to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ParentComponent.vue&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;       &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
           &lt;span class="nt"&gt;&amp;lt;ChildComponent&lt;/span&gt; &lt;span class="na"&gt;:message=&lt;/span&gt;&lt;span class="s"&gt;"message"&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;updateMessage=&lt;/span&gt;&lt;span class="s"&gt;"updateMessage"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

       &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ChildComponent&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./ChildComponent.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

       &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="na"&gt;components&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="nx"&gt;ChildComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="p"&gt;},&lt;/span&gt;
         &lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, Vue 3!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="p"&gt;};&lt;/span&gt;
         &lt;span class="p"&gt;},&lt;/span&gt;
         &lt;span class="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="nf"&gt;updateMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newMessage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newMessage&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
           &lt;span class="p"&gt;},&lt;/span&gt;
         &lt;span class="p"&gt;},&lt;/span&gt;
       &lt;span class="p"&gt;};&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ChildComponent.vue&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;       &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
           &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
           &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"updateParentMessage"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Update Parent Message&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

       &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="p"&gt;},&lt;/span&gt;
         &lt;span class="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="nf"&gt;updateParentMessage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;$emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;updateMessage&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;New message from child&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
           &lt;span class="p"&gt;},&lt;/span&gt;
         &lt;span class="p"&gt;},&lt;/span&gt;
       &lt;span class="p"&gt;};&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; In this example, the parent component (&lt;code&gt;ParentComponent&lt;/code&gt;) includes the child component (&lt;code&gt;ChildComponent&lt;/code&gt;). The parent component passes the &lt;code&gt;message&lt;/code&gt; prop to the child component, and listens to the &lt;code&gt;updateMessage&lt;/code&gt; event emitted by the child component. When the button is clicked in the child component, the &lt;code&gt;updateParentMessage&lt;/code&gt; method is called, which emits the &lt;code&gt;updateMessage&lt;/code&gt; event with a new message. The parent component's &lt;code&gt;updateMessage&lt;/code&gt; method is triggered and updates the &lt;code&gt;message&lt;/code&gt; property.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Scoped Styles:
&lt;/h3&gt;

&lt;p&gt;Vue 3 supports scoped styles, where CSS styles defined in the component's style section only apply to the component's template, preventing style conflicts with other components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;     &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

     &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, Vue 3!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="p"&gt;};&lt;/span&gt;
       &lt;span class="p"&gt;},&lt;/span&gt;
     &lt;span class="p"&gt;};&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

     &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;style&lt;/span&gt; &lt;span class="na"&gt;scoped&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;style&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; In this example, the component has a scoped style defined in the &lt;code&gt;style&lt;/code&gt; section. The &lt;code&gt;scoped&lt;/code&gt; attribute ensures that the style only applies to the component's template and doesn't affect other components. The style sets the text color of the &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; element to blue.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Slots:
&lt;/h3&gt;

&lt;p&gt;Slots allow components to receive and render content from the parent component.&lt;br&gt;
They provide a way to create flexible and customizable components.&lt;br&gt;
Components define slots in their template, and the parent component can pass content into the slots when using the component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ParentComponent.vue&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;       &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
           &lt;span class="nt"&gt;&amp;lt;ChildComponent&amp;gt;&lt;/span&gt;
             &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Slot content&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
           &lt;span class="nt"&gt;&amp;lt;/ChildComponent&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

       &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ChildComponent&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./ChildComponent.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

       &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="na"&gt;components&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="nx"&gt;ChildComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="p"&gt;},&lt;/span&gt;
       &lt;span class="p"&gt;};&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ChildComponent.vue&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;       &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
           &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
           &lt;span class="nt"&gt;&amp;lt;slot&amp;gt;&amp;lt;/slot&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

       &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, Vue 3!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="p"&gt;};&lt;/span&gt;
         &lt;span class="p"&gt;},&lt;/span&gt;
       &lt;span class="p"&gt;};&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; In this example, the parent component (&lt;code&gt;ParentComponent&lt;/code&gt;) includes the child component (&lt;code&gt;ChildComponent&lt;/code&gt;) and provides slot content between the opening and closing tags of the child component. The child component renders the provided slot content using the &lt;code&gt;&amp;lt;slot&amp;gt;&amp;lt;/slot&amp;gt;&lt;/code&gt; syntax. In this case, the slot content is a &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; element with the text "Slot content".&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Composition API:
&lt;/h3&gt;

&lt;p&gt;Vue 3 introduces the Composition API, which provides an alternative way to organize and reuse component logic.&lt;br&gt;
It allows you to group related logic together rather than separating it into options like data, methods, and computed properties.&lt;br&gt;
The Composition API provides hooks like reactive, computed, and watch to manage component state and reactivity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;     &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"changeMessage"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Change Message&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

     &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;reactive&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

     &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;reactive&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
           &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, Vue 3!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="p"&gt;});&lt;/span&gt;

         &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;changeMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;New message!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
         &lt;span class="p"&gt;};&lt;/span&gt;

         &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="nx"&gt;changeMessage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="p"&gt;};&lt;/span&gt;
       &lt;span class="p"&gt;},&lt;/span&gt;
     &lt;span class="p"&gt;};&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; In this example, the component uses the Composition API. The &lt;code&gt;setup&lt;/code&gt; function is the entry point for the Composition API. Inside the &lt;code&gt;setup&lt;/code&gt; function, the &lt;code&gt;reactive&lt;/code&gt; function is used to create a reactive object called &lt;code&gt;state&lt;/code&gt; with a &lt;code&gt;message&lt;/code&gt; property. The &lt;code&gt;changeMessage&lt;/code&gt; function updates the &lt;code&gt;message&lt;/code&gt; property. The &lt;code&gt;message&lt;/code&gt; property and the &lt;code&gt;changeMessage&lt;/code&gt; function are returned from the &lt;code&gt;setup&lt;/code&gt; function and made accessible in the component's template.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;, Components are a fundamental concept in Vue 3, empowering developers to build complex UIs by composing smaller, reusable units. With features like props, events, scoped styles, and the Composition API, components offer flexibility, maintainability, and code reusability in Vue 3 applications.&lt;br&gt;
The above examples illustrate the various aspects of components in Vue 3, including their structure, composition, data and props, lifecycle hooks, communication, scoped styles, slots, and the Composition API.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>vue</category>
    </item>
    <item>
      <title>Mastering Vue 3: A Comprehensive Guide to Building Modern Web Applications &lt;Part 6 /&gt;</title>
      <dc:creator>Hany Taha</dc:creator>
      <pubDate>Sat, 03 Feb 2024 16:35:42 +0000</pubDate>
      <link>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-1c6e</link>
      <guid>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-1c6e</guid>
      <description>&lt;h4&gt;
  
  
  Content:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-1--c75"&gt;Mastering Vue 3 - Part 1 [Introduction and key features]&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-2--1k0l"&gt;2. Mastering Vue 3 - Part 2 [Benefits of using Vue 3 for web development]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-3--fde"&gt;3. Mastering Vue 3 - Part 3 [Template syntax in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-19c0"&gt;4. Mastering Vue 3 - Part 4 [Reactivity Fundamentals]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-16g"&gt;5. Mastering Vue 3 - Part 5 [Class and Style Bindings]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Mastering Vue 3 - Part 6 [Lifecycle Hooks]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3nnd"&gt;7. Mastering Vue 3 - Part 7 [Understanding components in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-17ge"&gt;8. Mastering Vue 3 - Part 8 [Installing Vue project and file structure]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5d1p"&gt;9. Mastering Vue 3 - Part 9 [Vue Router in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4ig2"&gt;10. Mastering Vue 3 - Part 10 [Animation in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-53gh"&gt;11. Mastering Vue 3 - Part 11 [State Management with Pinia]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;12. Mastering Vue 3 - Part 12 [Teleport in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;13. Mastering Vue 3 - Part 13 [Working with API Calls ]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4bhi"&gt;14. Mastering Vue 3 - Part 14 [Forms and Form Validation ]&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Lifecycle Hooks
&lt;/h2&gt;

&lt;p&gt;In Vue 3, the concept of lifecycle hooks has been replaced with the Composition API, which provides a more flexible and intuitive way to manage component logic. Instead of using specific lifecycle hooks, you can use composition functions to encapsulate and reuse code.&lt;/p&gt;

&lt;p&gt;The Composition API introduces a set of functions that can be used inside the setup function of a component to define reactive data, computed properties, methods, and more. These functions are not tied to specific lifecycle stages, but rather allow you to organize your component logic in a more granular and composable way.&lt;/p&gt;

&lt;p&gt;Here are some important composition functions available in Vue 3:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;1. **setup function&lt;/u&gt;&lt;/strong&gt;:**&lt;br&gt;
The &lt;code&gt;setup&lt;/code&gt; function is the entry point of a component and is called before the component is created. It is where you define reactive data, computed properties, methods, and component setup logic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;reactive&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;computed&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;reactive&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, Vue 3!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;doubleCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;doubleCount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;increment&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;setup&lt;/code&gt; function defines reactive data (&lt;code&gt;state&lt;/code&gt;), a computed property (&lt;code&gt;doubleCount&lt;/code&gt;), and a method (&lt;code&gt;increment&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;2. **onMounted&lt;/u&gt;&lt;/strong&gt;:**&lt;br&gt;
The &lt;code&gt;onMounted&lt;/code&gt; function is used to perform actions when the component is mounted to the DOM. It is similar to the &lt;code&gt;mounted&lt;/code&gt; lifecycle hook in Vue 2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;onMounted&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;onMounted&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Component mounted&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;onMounted&lt;/code&gt; function is used to log a message when the component is mounted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;3. **onUpdated&lt;/u&gt;&lt;/strong&gt;:**&lt;br&gt;
The &lt;code&gt;onUpdated&lt;/code&gt; function is used to perform actions when the component is updated and re-rendered. It is similar to the &lt;code&gt;updated&lt;/code&gt; lifecycle hook in Vue 2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;onUpdated&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;onUpdated&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Component updated&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;onUpdated&lt;/code&gt; function is used to log a message when the component is updated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;4. **onUnmounted&lt;/u&gt;&lt;/strong&gt;:**&lt;br&gt;
The &lt;code&gt;onUnmounted&lt;/code&gt; function is used to perform cleanup actions when the component is unmounted from the DOM. It is similar to the &lt;code&gt;beforeUnmount&lt;/code&gt; lifecycle hook in Vue 2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;onUnmounted&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;onUnmounted&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Component unmounted&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;onUnmounted&lt;/code&gt; function is used to log a message when the component is unmounted.&lt;/p&gt;

&lt;p&gt;These are just a few examples of the composition functions available in the Composition API. By using these functions, you can organize your component logic in a more modular and reusable way, without being tied to specific lifecycle hooks.&lt;br&gt;
__&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>vue</category>
    </item>
    <item>
      <title>Mastering Vue 3: A Comprehensive Guide to Building Modern Web Applications &lt;Part 5 /&gt;</title>
      <dc:creator>Hany Taha</dc:creator>
      <pubDate>Fri, 02 Feb 2024 08:42:36 +0000</pubDate>
      <link>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-16g</link>
      <guid>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-16g</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Content:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-1--c75"&gt;Mastering Vue 3 - Part 1 [Introduction and key features]&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-2--1k0l"&gt;2. Mastering Vue 3 - Part 2 [Benefits of using Vue 3 for web development]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-3--fde"&gt;3. Mastering Vue 3 - Part 3 [Template syntax in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-19c0"&gt;4. Mastering Vue 3 - Part 4 [Reactivity Fundamentals]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Mastering Vue 3 - Part 5 [Class and Style Bindings]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-1c6e"&gt;6. Mastering Vue 3 - Part 6 [Lifecycle Hooks]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3nnd"&gt;7. Mastering Vue 3 - Part 7 [Understanding components in Vue 3&lt;br&gt;
]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-17ge"&gt;8. Mastering Vue 3 - Part 8 [Installing Vue project and file structure]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5d1p"&gt;9. Mastering Vue 3 - Part 9 [Vue Router in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4ig2"&gt;10. Mastering Vue 3 - Part 10 [Animation in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-53gh"&gt;11. Mastering Vue 3 - Part 11 [State Management with Pinia]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;12. Mastering Vue 3 - Part 12 [Teleport in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;13. Mastering Vue 3 - Part 13 [Working with API Calls ]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4bhi"&gt;14. Mastering Vue 3 - Part 14 [Forms and Form Validation ]&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Class and Style Bindings
&lt;/h2&gt;

&lt;p&gt;In Vue 3, class and style bindings allow you to dynamically apply CSS classes and inline styles to elements based on data or component state. This helps you create dynamic and responsive UIs by conditionally applying styles.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Class Bindings&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Class bindings allow you to conditionally apply CSS classes to elements. You can use the &lt;code&gt;v-bind:class&lt;/code&gt; directive or the shorthand &lt;code&gt;:class&lt;/code&gt; to bind a class dynamically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;:class=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;{ 'red': isError, 'bold': isBold }"&amp;gt;Some text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;isError&lt;/code&gt; and &lt;code&gt;isBold&lt;/code&gt; variables determine whether the &lt;code&gt;red&lt;/code&gt; and &lt;code&gt;bold&lt;/code&gt; classes should be applied to the &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; element, respectively. If &lt;code&gt;isError&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;, the &lt;code&gt;red&lt;/code&gt; class will be applied. If &lt;code&gt;isBold&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;, the &lt;code&gt;bold&lt;/code&gt; class will be applied.&lt;/p&gt;

&lt;p&gt;You can also use an object syntax to conditionally apply classes based on the truthiness of properties:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;:class=&lt;/span&gt;&lt;span class="s"&gt;"classObject"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Some text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;classObject&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bold&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;classObject&lt;/code&gt; data property defines the classes to be applied. The &lt;code&gt;red&lt;/code&gt; class is applied because its value is &lt;code&gt;true&lt;/code&gt;, while the &lt;code&gt;bold&lt;/code&gt; class is not applied because its value is &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Style Bindings&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Style bindings allow you to apply inline styles to elements dynamically. You can use the &lt;code&gt;v-bind:style&lt;/code&gt; directive or the shorthand &lt;code&gt;:style&lt;/code&gt; to bind styles.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;:style=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;{ color: textColor, fontSize: fontSize + 'px' }"&amp;gt;Some text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;textColor&lt;/code&gt; and &lt;code&gt;fontSize&lt;/code&gt; variables determine the color and font size of the text, respectively. The &lt;code&gt;color&lt;/code&gt; style is bound to the &lt;code&gt;textColor&lt;/code&gt; variable, and the &lt;code&gt;fontSize&lt;/code&gt; style is bound to the &lt;code&gt;fontSize&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;You can also bind styles directly to a style object in your component’s data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;:style=&lt;/span&gt;&lt;span class="s"&gt;"textStyle"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Some text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;textStyle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;fontSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;20px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;textStyle&lt;/code&gt; data property defines the styles to be applied. The text will be displayed in red with a font size of 20 pixels.&lt;/p&gt;

&lt;p&gt;Both class and style bindings can be combined and used together within the template.&lt;/p&gt;

&lt;p&gt;These class and style bindings in Vue 3 provide a flexible way to apply dynamic styles and classes based on component data or state, allowing you to create more interactive and responsive user interfaces.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>vue</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Mastering Vue 3: A Comprehensive Guide to Building Modern Web Applications &lt;Part 4 /&gt;</title>
      <dc:creator>Hany Taha</dc:creator>
      <pubDate>Fri, 02 Feb 2024 08:37:24 +0000</pubDate>
      <link>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-19c0</link>
      <guid>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-19c0</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Content:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-1--c75"&gt;Mastering Vue 3 - Part 1 [Introduction and key features]&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-2--1k0l"&gt;2. Mastering Vue 3 - Part 2 [Benefits of using Vue 3 for web development]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-3--fde"&gt;3. Mastering Vue 3 - Part 3 [Template syntax in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Mastering Vue 3 - Part 4 [Reactivity Fundamentals]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-16g"&gt;5. Mastering Vue 3 - Part 5 [Class and Style Bindings]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-1c6e"&gt;6. Mastering Vue 3 - Part 6 [Lifecycle Hooks]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3nnd"&gt;7. Mastering Vue 3 - Part 7 [Understanding components in Vue 3&lt;br&gt;
]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-17ge"&gt;8. Mastering Vue 3 - Part 8 [Installing Vue project and file structure]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5d1p"&gt;9. Mastering Vue 3 - Part 9 [Vue Router in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4ig2"&gt;10. Mastering Vue 3 - Part 10 [Animation in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-53gh"&gt;11. Mastering Vue 3 - Part 11 [State Management with Pinia]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;12. Mastering Vue 3 - Part 12 [Teleport in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;13. Mastering Vue 3 - Part 13 [Working with API Calls ]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4bhi"&gt;14. Mastering Vue 3 - Part 14 [Forms and Form Validation ]&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Reactivity Fundamentals in Vue 3
&lt;/h2&gt;

&lt;p&gt;Reactivity is a core concept in Vue 3 that enables automatic updating of the user interface when the underlying data changes. It allows you to build dynamic and reactive applications without manually managing the DOM.&lt;/p&gt;

&lt;p&gt;Vue 3 introduces a new reactivity system called the Composition API, which is built on top of the underlying reactivity system known as the Reactivity API. The Reactivity API provides the foundation for the Composition API and is responsible for tracking dependencies and triggering updates when data changes.&lt;/p&gt;

&lt;p&gt;The key components of the Reactivity API in Vue 3 are:&lt;/p&gt;
&lt;h2&gt;
  
  
  Reactive
&lt;/h2&gt;

&lt;p&gt;The reactive function is used to create a reactive proxy object from a plain JavaScript object. The reactive proxy wraps the original object and allows Vue to track its properties, so that any changes to those properties can be detected.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;reactive&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;reactive&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the state object is made reactive using the reactive function. Now, any changes to the message or count properties will be automatically detected by Vue.&lt;/p&gt;




&lt;h2&gt;
  
  
  Ref
&lt;/h2&gt;

&lt;p&gt;The ref function is used to create a reactive reference to a value. Unlike reactive objects, which track properties, refs track individual values. You can think of refs as reactive wrappers around primitive values or objects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the count variable is a ref that holds the value 0. Whenever the value of count changes, Vue will automatically detect the update and trigger reactivity.&lt;/p&gt;




&lt;h2&gt;
  
  
  Computed
&lt;/h2&gt;

&lt;p&gt;The computed function allows you to create computed properties that automatically update when their dependencies change. Computed properties are derived values based on other reactive data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;computed&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;doubleCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the doubleCount computed property calculates the value of count * 2 based on the count ref. Whenever the count ref changes, the doubleCount computed property will automatically recompute its value.&lt;/p&gt;




&lt;h2&gt;
  
  
  Watch
&lt;/h2&gt;

&lt;p&gt;The watch function allows you to perform side effects or respond to changes in reactive data. You can watch a single reactive value or an array of reactive values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;watch&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;oldValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Count changed from &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;oldValue&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; to &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;newValue&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the watch function is used to watch changes in the count ref. Whenever the value of count changes, the callback function will be executed with the new and old values.&lt;/p&gt;

&lt;p&gt;These are the fundamental concepts of reactivity in Vue 3. By leveraging the Reactivity API, you can build reactive components and applications that automatically update the UI based on changes in data. The Composition API builds upon the Reactivity API, providing more powerful and flexible ways to organize and reuse reactive code in your Vue 3 applications.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>vue</category>
    </item>
    <item>
      <title>Mastering Vue 3: A Comprehensive Guide to Building Modern Web Applications &lt; Part 3 /&gt;</title>
      <dc:creator>Hany Taha</dc:creator>
      <pubDate>Fri, 02 Feb 2024 08:23:00 +0000</pubDate>
      <link>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-3--fde</link>
      <guid>https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-3--fde</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Content:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-1--c75"&gt;Mastering Vue 3 - Part 1 [Introduction and key features]&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-part-2--1k0l"&gt;2. Mastering Vue 3 - Part 2 [Benefits of using Vue 3 for web development]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Mastering Vue 3 - Part 3 [Template syntax in Vue 3]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-19c0"&gt;4. Mastering Vue 3 - Part 4 [Reactivity Fundamentals]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-16g"&gt;5. Mastering Vue 3 - Part 5 [Class and Style Bindings]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-1c6e"&gt;6. Mastering Vue 3 - Part 6 [Lifecycle Hooks]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-3nnd"&gt;7. Mastering Vue 3 - Part 7 [Understanding components in Vue 3&lt;br&gt;
]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-17ge"&gt;8. Mastering Vue 3 - Part 8 [Installing Vue project and file structure]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5d1p"&gt;9. Mastering Vue 3 - Part 9 [Vue Router in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4ig2"&gt;10. Mastering Vue 3 - Part 10 [Animation in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-53gh"&gt;11. Mastering Vue 3 - Part 11 [State Management with Pinia]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;12. Mastering Vue 3 - Part 12 [Teleport in Vue 3]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-5h64"&gt;13. Mastering Vue 3 - Part 13 [Working with API Calls ]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hanytaha61/mastering-vue-3-a-comprehensive-guide-to-building-modern-web-applications-4bhi"&gt;14. Mastering Vue 3 - Part 14 [Forms and Form Validation ]&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;Template syntax in Vue 3&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In Vue 3, the template syntax is used to define the structure and rendering logic of a component's HTML markup. It provides a declarative way to describe how the component should look based on its data and state.&lt;br&gt;
The template syntax in Vue 3 is similar to the previous versions of Vue, but with a few changes and enhancements. Here are some key aspects of the template syntax in Vue 3:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;Interpolation&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Interpolation allows you to insert dynamic values into the template. It uses double curly braces &lt;code&gt;{{ }}&lt;/code&gt; to bind the data to the template.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello world&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
              &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
          &lt;span class="p"&gt;};&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the message and count variables are dynamically inserted into the paragraphs.&lt;br&gt;
Note: variables must be defined in the data function.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;Directives&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Directives are special attributes starting with the v- prefix that provide additional functionality to elements or components. They are used to bind data, control rendering, handle events, and more.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;v-if=&lt;/span&gt;&lt;span class="s"&gt;"showMessage"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"increment"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Increment&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the v-if directive conditionally renders the paragraph based on the value of showMessage, and the @click directive attaches an event listener to the button that triggers the increment method.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;Conditionals&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Vue 3 provides conditional rendering directives to show or hide elements based on certain conditions. The most commonly used directives for conditionals are v-if, v-else, v-else-if, and v-show.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;v-if=&lt;/span&gt;&lt;span class="s"&gt;"showMessage"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Message is shown&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;v-else-if=&lt;/span&gt;&lt;span class="s"&gt;"count &amp;gt; 10"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Count is greater than 10&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;v-else&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Default message&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the paragraph elements are conditionally rendered based on different conditions.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;em&gt;List Rendering&lt;/em&gt;&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Vue 3 provides the v-for directive for rendering lists or iterating over arrays or objects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;v-for=&lt;/span&gt;&lt;span class="s"&gt;"item in items"&lt;/span&gt; &lt;span class="na"&gt;:key=&lt;/span&gt;&lt;span class="s"&gt;"item.id"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the v-for directive iterates over the items array and renders an &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; element for each item.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;em&gt;Event Handling&lt;/em&gt;&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Vue 3 allows you to handle user-interactions and events using the v-on directive or the shorthand @ symbol.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"increment"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Increment&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the @click directive attaches an event listener to the button, triggering the increment method when clicked.&lt;/p&gt;

&lt;p&gt;These are some examples of the template syntax in Vue 3. The template syntax provides a convenient way to define the structure and behavior of the component's HTML markup, making it easy to build dynamic and reactive user interfaces.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>vue</category>
    </item>
  </channel>
</rss>
