<?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>Forem: Gloria Ngbea</title>
    <description>The latest articles on Forem by Gloria Ngbea (@ngbeagloriajames).</description>
    <link>https://forem.com/ngbeagloriajames</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%2F1284768%2F9cdeb7cb-cecc-4303-a560-c6d183bec5c1.jpeg</url>
      <title>Forem: Gloria Ngbea</title>
      <link>https://forem.com/ngbeagloriajames</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ngbeagloriajames"/>
    <language>en</language>
    <item>
      <title>How to make a simple incremental, decremental, and Reset Counter App with Vue.js for a beginner</title>
      <dc:creator>Gloria Ngbea</dc:creator>
      <pubDate>Sun, 25 Feb 2024 21:27:52 +0000</pubDate>
      <link>https://forem.com/ngbeagloriajames/how-to-make-a-simple-incremental-decremental-and-reset-counter-app-with-vuejs-for-a-beginner-21kl</link>
      <guid>https://forem.com/ngbeagloriajames/how-to-make-a-simple-incremental-decremental-and-reset-counter-app-with-vuejs-for-a-beginner-21kl</guid>
      <description>&lt;p&gt;Dear Readers,&lt;/p&gt;

&lt;p&gt;Welcome! In this guide, I'll walk you through the process of creating a counter app using Vue.js. Whether you're new to web development or looking to expand your skills, this project is designed to be beginner-friendly.&lt;/p&gt;

&lt;p&gt;Lets get into it&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites and Dependencies:
&lt;/h2&gt;

&lt;p&gt;Before we begin, make sure you have a basic understanding of JavaScript. Familiarity with concepts like variables, functions, and event handling will be helpful. Vue.js is a progressive JavaScript framework that makes building user interfaces straightforward and efficient.&lt;/p&gt;

&lt;p&gt;To get started, we'll use a Content Delivery Network (CDN) to host Vue.js. A CDN delivers files like JavaScript libraries quickly to users around the world. You can find the necessary script tag by visiting &lt;/p&gt;

&lt;h2&gt;
  
  
  Step-by-step installation instructions
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Visit &lt;a href="https://vuejs.org/" rel="noopener noreferrer"&gt;vuejs.org&lt;/a&gt; and navigate to &lt;a href="https://vuejs.org/guide/quick-start.html#using-vue-from-cdn" rel="noopener noreferrer"&gt;Using Vue from CDN&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Copy the provided script tag.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flgkfx8l938lwlvqmj0mv.png" alt="Image description"&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a folder for your counter app project and paste the script tag into the head section of your HTML file.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftv3hjqkuk02e0u9tamah.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftv3hjqkuk02e0u9tamah.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
NOTE: &lt;em&gt;Placing the script tag in the head tag ensures optimal loading priority and parsing efficiency.&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a root element &lt;code&gt;&amp;lt;div class="app"&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt; in your HTML file.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Note: The convention of naming the root div "app" is commonly used in Vue.js projects created with tools like Vue CLI, but it's not a strict requirement. You can name it anything you like, and you can also use a class instead of an id. Whatever name or selector you give to the root element is what you'll use to mount your Vue instance..&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Let's delve into building the counter app itself..&lt;/p&gt;

&lt;p&gt;Create an external JavaScript file and ensure you have a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag within the HTML &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; section to link to that JavaScript file. Once that is done go to the external JavaScript file and create a Vue instance by using this block of code &lt;code&gt;Vue.createApp()&lt;/code&gt; is a method provided by Vue.js that initializes and creates a Vue application instance&lt;br&gt;
followed by   &lt;code&gt;data() { return{ } }&lt;/code&gt; The data() method is part of the Vue instance options. It is used to define the initial state of the data properties for your Vue application. Typically, you would define your application's initial data properties within this method.&lt;/p&gt;

&lt;p&gt;Note: * The letter V in Vue' must be capitalized to function correctly."* Doing that initializes and creates a Vue instance, making it the starting point for building Vue applications. Next app.mount('#app'): This line mounts the Vue application instance to an HTML element with the ID app. This means that the Vue application will control and render content within this HTML element.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Counter App
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flcpwfqos9usqejf1k0g4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flcpwfqos9usqejf1k0g4.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
The Simple Counter App I developed features buttons for increasing, decreasing, and resetting the count to zero, followed by a display area to showcase these actions. These buttons allow users to manipulate the count displayed by the app. Let's get into how made each one of them functional.&lt;/p&gt;

&lt;h4&gt;
  
  
  HTML CODE
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgcyniovcr04ae0zhrgqb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgcyniovcr04ae0zhrgqb.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  app.js CODE
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhhuvxci6ci90a5ivgeb1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhhuvxci6ci90a5ivgeb1.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  - Display Area for showcasing the Counter App actions
&lt;/h3&gt;

&lt;p&gt;Define an object within the Vue instance.&lt;br&gt;
This object will be be  returned by the data method. It defines a single property named count with an initial value of 0 for the &lt;em&gt;display area&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcx5l6us5zbt63fi1d8gy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcx5l6us5zbt63fi1d8gy.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is Vue.js template syntax for data binding. It will display the value of the count variable in the paragraph. Whenever the count variable changes in the Vue instance, the displayed value in the paragraph also updates automatically, reflecting the new value of count. I went ahead to create an event lister that listens for the click event and then defined a function that occurs once the the display area is clicked here is the function defined &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F70x6yclr490qb90zzk6f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F70x6yclr490qb90zzk6f.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A constant is created called "digit" that prompts you to enter a digit, and then it gives a condition that if no digit is entered, it should return the current count in the display area; else if the digit is a valid number, it should display the number inputted in the prompt.&lt;br&gt;
&lt;em&gt;The below is the function for the clicked event&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz4q74x36gb4i4a4z4fji.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz4q74x36gb4i4a4z4fji.png" alt="Image description"&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Increment, Decrement and Reset Button.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpz3jdeypkfldpvmv5ei.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpz3jdeypkfldpvmv5ei.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  The Increment Button.
&lt;/h4&gt;

&lt;p&gt;Here I used the plus sign &lt;code&gt;+&lt;/code&gt; to represent the increment button. I simply used v-on which is a Vue.js directive that attaches an event listener to the add button and increases the value of count by 1 &lt;code&gt;count++&lt;/code&gt;when the button is clicked.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Decrement Button.
&lt;/h4&gt;

&lt;p&gt;Similar to the Increment button Here I used the minus or subtraction sign &lt;code&gt;-&lt;/code&gt; to represent the decrement button. I used v-on which is a Vue.js directive that attaches an event listener to the add button and decreases the value of count by 1 &lt;code&gt;count--&lt;/code&gt;when the button is clicked.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Reset Button.
&lt;/h4&gt;

&lt;h5&gt;
  
  
  The HTML CODE
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm7c0fayjf3bfnqsttthg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm7c0fayjf3bfnqsttthg.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  The Reset Function
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnjco9lasozvbsvwz0kqs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnjco9lasozvbsvwz0kqs.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I created a function designed to reset count to zero. Within the HTML file, there's an event listener that detects a click on a reset button. Once the reset button is clicked, it triggers the execution of the function responsible for resetting the count to zero .&lt;/p&gt;

&lt;h2&gt;
  
  
  The Output of the Counter App
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpd5mol6zjf2nrn91kj9z.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpd5mol6zjf2nrn91kj9z.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  GitHub Repository for this project:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/NgbeaGloriaJames/Counter-App-with-Vue-CDN" rel="noopener noreferrer"&gt;https://github.com/NgbeaGloriaJames/Counter-App-with-Vue-CDN&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Counter App:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://vue-counter-app-gloria-ngbea.netlify.app/" rel="noopener noreferrer"&gt;https://vue-counter-app-gloria-ngbea.netlify.app/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>html</category>
      <category>css</category>
    </item>
  </channel>
</rss>
