Vuejs: Difference between revisions

From Training Material
Jump to navigation Jump to search
Line 94: Line 94:
* '''Component Pattern''' instead of '''MVC'''
* '''Component Pattern''' instead of '''MVC'''
* Constructs
* Constructs
** '''Interpolation''', '''expressions''', '''data binding''' syntax
** '''expressions''', '''data binding''' syntax
* Change detection
* Change detection
* Web components
* Web components


<!--
==== Component pattern ⌘====
==== Component pattern ⌘====
* In general, involves combining smaller, discrete building blocks into larger finished products
* In software development, '''logical units''' that can be combined into '''larger applications'''
** Tend to have '''internal logic''' and properties that are '''shielded''' or '''hidden''' from the larger application
** The larger application consumes these building-blocks through specific '''gateways''' (interfaces)
*** That expose only what is needed to make use of the component
** Component's internal logic can be modified '''without affecting''' the larger application
*** As long as the '''interfaces''' are not changed
==== Component pattern Con't ⌘====
In web applications  
In web applications  
* No messes of spaghetti code in applications
* No messes of spaghetti code in applications
Line 116: Line 106:
** No affecting the other parts of the application
** No affecting the other parts of the application
* '''Self-describing''' components
* '''Self-describing''' components
** Makes the application easier to understand at a higher level of abstraction
** Makes the application easier to understand at a '''higher level of abstraction'''


==== Constructs ⌘====
==== Constructs ⌘====
* Usually they live in the HTML template that is inside the ''@Component'' '''decorator'''
* Usually they live in the HTML template
* They are '''linking''' the view HTML and component code
* They are '''linking''' the view HTML and component code
* Similar to standard HTML with new symbols:<syntaxhighlight lang="js">
* Similar to standard HTML with new symbols:<syntaxhighlight lang="js">
[ ] property bindings
: property bindings (v-bind)
( ) event bindings
@ event bindings (v-on)
{{ }} interpolation
{{ }} expressions (interpolation)
</syntaxhighlight>
</syntaxhighlight>


<!--
==== Interpolation ⌘====
==== Interpolation ⌘====
* Replaces the content of the '''markup''' with the value of the expression ('''howManyTries''')
* Replaces the content of the '''markup''' with the value of the expression ('''howManyTries''')

Revision as of 10:18, 13 May 2024


Vuejs

Vuejs Training Materials

Introduction

  • JavaScript framework for building UI (user interfaces)
  • What do we need?
    • HTML, CSS, and JavaScript
  • Declarative, component-based programming model
    • Declarative rendering
    • Reactivity
  • Progressive framework
  • Single-file components (SFC)
  • API Styles - options VS composition

Not That

NotVue.png

BUT still - we'll have a lot to see! (-'

Framework

Progressive Framework - "framework that can grow with you and adapt to your needs"

  • framework and ecosystem
  • designed to be flexible and incrementally adoptable
  • can be used in
    • enhancing static HTML without a build step
    • embedding as Web Components on any page
    • Single-Page Application (SPA)
    • Fullstack / Server-Side Rendering (SSR)
    • Jamstack / Static Site Generation (SSG)
    • targeting desktop, mobile, WebGL, and even the terminal

Overview of Vue JS

  • Declarative rendering
  • Component composition
  • Hot-reloading
  • Time-travel debugging

Declarative rendering

Component composition

Hot-reloading

Time-travel debugging

Setting up a development environment

vue itself

npm create vue@latest

Creating your first application

Build game "Find the jewel".
The objective of the game is to find a random computer-chosen jewel in as few tries as possible.

Approach:
* First think about the functionality we want to offer
* Second think about the data and behavior that can support the functionality
* Third think about how to build a user interface for it

Test it with 'live-server' (if not yet installed in the training machine, run 'sudo npm i -g live-server')
* in command line go to application's root folder and execute the command 'live-server --cors'
  1. Designing the component
    • Detailing the features that we want the app to support
      • Choosing random jewel (origJewel)
      • Providing input for a user to find the jewel (findJewel)
      • Tracking the number of tries already made (howManyTries)
      • Giving the user hints to improve their try based on their input (hinting)
      • Giving a success message if the user found the proper jewel (hinting)
    • Determining what we need to display to the user and what data we need to track
      • Names in round brackets above are the properties that will support those features
      • We need to include these properties in our component

Working with Templates

Dividing the application into smaller, self-contained components

  • Component Pattern instead of MVC
  • Constructs
    • expressions, data binding syntax
  • Change detection
  • Web components

Component pattern ⌘

In web applications

  • No messes of spaghetti code in applications
  • Reasoning about specific parts of the application in isolation from the other parts
  • Maintenance costs are less
    • Each component's internal logic can be managed separately
    • No affecting the other parts of the application
  • Self-describing components
    • Makes the application easier to understand at a higher level of abstraction

Constructs ⌘

  • Usually they live in the HTML template
  • They are linking the view HTML and component code
  • Similar to standard HTML with new symbols:
    : property bindings (v-bind)
    @ event bindings (v-on)
    {{ }} expressions (interpolation)
    


Methods and computed properties

Reactive programming

Directives and data rendering

Applying transitions

Routing

Managing state

Creating animations

Refactoring components

Server-side rendering

Supporting libraries and packages

  • Routing
  • State management
  • Build tooling

Routing

State management

Build tooling

Testing your application

Debugging and performance

Embedding Vue.js into existing pages

Deploying your application to production Vue-CLI

  • Vite as a replacement for Vue-CLI
    • npm run dev
    • npm run build
    • interactive CLI commands:
press r + enter to restart the server
press u + enter to show server url
press o + enter to open in browser
press c + enter to clear console
press q + enter to quit

Scaling your application

Helpers