thema 2a components props

Table of contents

  1. Extra & Recap Week 1
  2. DIY - Combination Exercise: Calculating VAT
  3. Buying Tickets
  4. Components
  5. Displaying Products
  6. Chemical Elements

1. Extra & Recap Week 1

1.1 Extra installations

This section covers additional tools that can be installed to enhance the web development environment. These include extensions for Visual Studio Code and Chrome 3.

  • Visual Studio Code Extension: The Vue Language Features (Volar) extension is recommended for improved Vue.js development support within Visual Studio Code.
  • Chrome Extension: The Vue.js devtools beta extension for Chrome allows for debugging and inspecting Vue.js applications directly in the browser 3.

1.2 Recap of learned concepts

This section summarizes the core concepts covered in Vue.js up to this point, highlighting skills that students should already possess 5.

  • Project Creation: Students should be able to initiate new Vue.js projects.
  • Vue Component Structure: Understanding the different parts of a Vue component, including the script, template, and style sections.
  • Scripting in Vue: Proficiency in writing code within the <script> section, utilizing features like script setup and refs.
  • Declarative Rendering: The ability to render data and logic directly within the HTML template section.
  • Directives: Familiarity with common Vue directives such as v-if for conditional rendering, v-model for two-way data binding, and v-for for list rendering 5.

A user interface element for calculating VAT, showing an input field for the amount and radio buttons to select whether VAT is included or excluded.

📝 A VAT calculator interface might feature an input field for the total amount and radio buttons to specify if VAT is already included or needs to be added. This allows users to input a price and see the breakdown of the base amount and the VAT amount .

2. DIY - Combination Exercise: Calculating VAT

2.1 Calculating VAT

This exercise involves creating an input field to calculate Value Added Tax (VAT), also known as BTW in Dutch. The functionality will allow users to input an amount and specify whether the entered amount already includes VAT or if VAT needs to be added.

The calculation will focus on the standard 21% VAT rate 6 8.

The core of the calculation relies on simple mathematical operations to determine the base amount and the VAT amount. The user interface will include an input field for the monetary amount and radio buttons to select whether the entered amount is inclusive or exclusive of VAT 8.

The calculations for VAT are as follows:

  • Amount without VAT: To find the base amount when the entered value includes VAT, divide the entered amount by 1.21.
  • Amount with VAT: To find the amount including VAT when starting with the base amount, multiply the base amount by 1.21 9.
ScenarioCalculation
Amount without VAT (given amount includes VAT)Amount without VAT = Entered Amount / 1.21
Amount with VAT (given amount is base amount)Amount with VAT = Base Amount * 1.21

The exercise also prompts for basic styling to enhance the user interface 8.

3. Buying Tickets

3.1 Ticket purchasing mini-site

This section outlines the creation of a mini-website for purchasing train tickets, focusing on calculating costs based on the number of tickets and applying CSS styling. The goal is to build a functional interface for ticket selection and cost calculation 11.

  • Core functionality: The mini-site will allow users to select and purchase train tickets.
  • Cost calculation: The system will dynamically calculate the total cost based on the number of tickets selected.
  • Styling: CSS will be used to ensure the website has a neat and visually appealing appearance 11 13.

3.2 Ticket purchasing interface

The development process begins with structuring the HTML for the ticket purchasing interface, followed by implementing dynamic features using Vue.js. Key considerations include defining ticket prices, managing totals, and applying styles 12.

  • HTML structure: Start by writing the basic HTML for the interface.
  • Vue.js implementation: Identify elements that can be directly implemented in Vue.js, such as ticket prices and total cost calculations.
  • Styling approach: Decide whether to integrate styles immediately or after the core functionality is in place 12.

The interface includes sections for ticket selection and an overview of the purchase. For example, a user might select tickets for the Trans-Siberian Railway 12.

📝 A user might select tickets for the Trans-Siberian Railway, with options to add adult tickets at EUR 1200 each and children's tickets at EUR 800 each 12.

3.3 Ticket cost calculation

This section focuses on the CSS required to style the ticket purchasing interface and the logic for calculating ticket costs. The primary goal is to present a clear overview of selected tickets and their total price 13.

  • CSS styling: Implement CSS to ensure the interface is visually organized and appealing.
  • Ticket selection: Users can select tickets for different categories, such as adults and children.
  • Cost breakdown: The overview displays the number of tickets per category and their individual prices 13.

The total cost for this example purchase is EUR 7,600 13.

4. Components

4.1 What are components?

Components are reusable visual elements that form the building blocks of a website. They offer a more structured and efficient way to build complex web interfaces, especially within frameworks like Vue.js. The core idea is to break down a user interface into smaller, manageable, and independent parts 14 20.

  • HTML elements as basic building blocks: Websites are built using HTML elements that serve specific functions, such as images, tables, addresses, and lists 16.
  • The need for better structure: Repeated HTML structures for similar items indicate a need for a more organized approach 17 18.
  • Reusability and dynamic content: Components allow for the creation of identical HTML structures that can be used multiple times, with variations handled dynamically 19.
  • Framework integration: Components are heavily utilized within web frameworks like Vue.js to create reusable visual elements 20 21.

4.2 Creating and structuring components

Components are a fundamental concept in modern web development, particularly in frameworks like Vue.js. They represent reusable visual elements that streamline the development process 23.

  • Component naming convention: A component always starts with a capital letter, for example, CookieMessage.vue or GenericButton.vue.
  • Strategic component design: The focus is on deciding which components are necessary and when to create a new component versus modifying an existing one due to significant deviations 23.
  • Placement of components: Components are typically placed in a /components folder, which can later be further organized into subdirectories 25.

4.3 The three basic elements of a component

A typical component, especially in Vue.js, is structured into three fundamental parts: template, script, and style 22.

A diagram illustrating the three basic elements of a Vue.js component: template, script, and style.

  • Template (HTML): This section contains the HTML structure of the component, including standard HTML tags and Vue-specific directives.
  • Script (JavaScript): This section holds the component's logic, written in a specific manner compatible with the framework.
  • Style (CSS/SCSS): This section defines the component's appearance using CSS or SCSS, including classes for styling 22.

4.4 Component design principles

Effective component design involves making deliberate choices about what to include and exclude to maintain reusability and clarity 24.

  • 👍 What to do:
  • Focus on logical separation: It is better to divide functionality into two main parts, such as a PrimaryButton and a SiteHeader, rather than creating overly complex components.
  • 👎 What not to do:
  • Avoid mimicking existing HTML: Do not create components that simply replicate standard HTML elements like <header>.
  • Prevent excessive component content: Components should not be given too much internal content or responsibility 24.

4.5 Creating a component

The component itself is structured as a Vue component, containing its own template 25.

A file explorer view showing a 'components' folder containing a 'CustomComponent.vue' file.

4.6 Dynamic components with props

Props allow specific data to be passed into a component, making it reusable and dynamic. These props are defined within the component and set externally when the component is used 26.

const props = defineProps({ message: String, })

4.7 Using props

Props are read-only and cannot be modified within the component after they are received. They must always be defined, specifying the expected data type 27.

Data TypeDescription
StringTextual data
NumberNumerical data
BooleanTrue or false values
ArrayOrdered list of values
ObjectCollection of key-value pairs
DateDate and time values
FunctionReusable block of code
SymbolUnique and immutable values

5. Displaying Products

5.1 Product display component

This section focuses on creating a reusable component to display product information. The goal is to iterate through a list of products and render each one using a dedicated component, passing necessary data as props 29.

The design for the product display includes the product's price, name, and a brief description 30.

This diagram illustrates how to define and use props in a component, showing the code for defining props and an example of passing a prop to a component.

  • Component reusability: Components allow for the same UI element to be used multiple times with different data.
  • Props: These are custom attributes that you can pass from a parent component to a child component, enabling data flow and customization 26.

5.2 Product component props

To display individual products effectively, a component needs specific properties, or props, to receive the relevant data 29.

The essential props for a product component include:

  • Price: The cost of the product.
  • Name: The title or name of the product.
  • Description: A short text explaining the product 30.

5.3 Example: Displaying products

This example demonstrates how to structure a Vue application to display a list of products using a reusable Product component 29.

The application would typically have a parent component that holds the product data and renders multiple instances of the Product component, passing each product's details as props 26.

The file structure would likely include a components folder containing the Product.vue file 25.

📝 Imagine a list of products like this:

[
{ "name": "Klippan", "price": 249, "description": "A compact and comfortable bank for small spaces." },
{ "name": "Ektorp", "price": 449, "description": "A classic and timeless bank with a removable cover." }

Each of these objects would be passed as props to a Product component, which would then render the name, price, and description for each 29 30.

6. Chemical Elements

6.1 Introduction to Chemical Elements

Chemical elements are the fundamental building blocks of matter, each defined by its unique atomic number. The provided figure illustrates a selection of elements, displaying their names, atomic numbers, symbols, and atomic masses, which are crucial identifiers in chemistry 31.

A selection of elements from the periodic table, showing their names, atomic numbers, symbols, and their atomic masses.

6.2 Selected Chemical Elements

The following table lists several chemical elements with their corresponding atomic number, symbol, and atomic mass. The atomic number indicates the number of protons in an atom's nucleus, defining the element.

The symbol is a one or two-letter abbreviation for the element's name, and the atomic mass is the average mass of atoms of an element, calculated using the relative abundance of isotopes 31.

ElementAtomic NumberSymbolAtomic Mass
Hydrogen1H1.008
Helium2He4.0026
Lithium3Li6.94
Beryllium4Be9.0122
Boron5B10.81
Carbon6C12.011
Nitrogen7N14.007
Oxygen8O15.999
Fluorine9F18.998
Neon10Ne20.18

© 2026 Maeve. All rights reserved. This content is protected by copyright.

See also