SlideShare a Scribd company logo
Vue.js
Getting Started
Murat Dogan – Sr. Front End Developer @ Hurriyet
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
• What is Vue.js ?
• Comparison with other libraries/frameworks
• SFC Concept
• Getting Started with Vue.js
• Basic Vue.js Features
• Creating a development environment in 1 min
• Okur Temsilcisi Vue.js Edition / Vue Router
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
How to choose the right framework?
• How mature are the frameworks / libraries?
• Are the frameworks likely to be around for a while?
• How extensive and helpful are their corresponding communities?
• How easy is it to find developers for each of the frameworks?
• What are the basic programming concepts of the frameworks?
• How easy is it to use the frameworks for small or large applications?
• What does the learning curve look like for each framework?
• What kind of performance can you expect from the frameworks?
• Where can you have a closer look under the hood?
• How can you start developing with the chosen framework?
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Latest News : 11th September
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
What is Vue.js?
• Vue (pronounced /vju /, likeː view) is a progressive framework for building user
interfaces.1
• It was first released in February 2014 by ex-Google-employee Evan You
• Only thing you need to know is HTML, CSS and JavaScript
• It’s been popular since its last version 2.0
• Vue is used by Alibaba, Baidu, Expedia, Nintendo, GitLab—a list of smaller projects can be   
found on madewithvuejs.com.
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Comparison with other libraries/frameworks
Based on 3rd party benchmark, lower is better
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Installing Vue.js
•You can install core library via CDN (Content Delivery Network)
•If you want to always follow up the latest version of Vue, use unpkg:
• https://unpkg.com/vue - Always redirect to the latest version of Vue!
• https://unpkg.com/vue@[version]/dist/vue.min.js - to specific version.
•You can install core library using Bower or npm
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Getting Started – Hello World
•Open https://jsfiddle.net, choose the additional JS Framework; Vue.js
•JavaScript section :
• new Vue({el:'#app'})
•HTML section:
• <div id="app"> {{'Hello ' + 'world'}} </div>
•Result:
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
How it works...
new Vue({el:'#app'}) will instantiate a new Vue instance. It accepts an options object as a parameter. This object is central
in Vue, and defines and controls data and behavior. It contains all the information needed to create Vue instances and
components. In our case, we only specified the el option which accepts a selector or an element as an argument.
The #app parameter is a selector that will return the element in the page with app as the identifier. For example, in a
page like this:
Everything that we will write inside the <div> with the ID as app will be
under the scope of Vue.
Now, JSFiddle takes everything we write in the HTML quadrant and wraps it
in body tags. This means that if we just need to write the <div> in the HTML
quadrant, JSFiddle will take care of wrapping it in the body tags.
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
It's also important to note that placing the #app on the body or html tag will
throw an error, as Vue advises us to mount our apps on normal elements, and
its the same thing goes for selecting the body in the el option.
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Lifecycle Diagram
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Lifecycle Diagram Example
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Interpolations
Text Raw Html
this will also affect any binding on the same node
Attributes
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Interpolations - JavaScript Expressions
So far we’ve only been binding to simple property keys in our templates. But Vue.js actually supports the full power of
JavaScript expressions inside all data bindings
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Directives
Directives are special attributes with the v- prefix. Directive attribute values are expected to be a single JavaScript
expression (with the exception for v-for, which will be discussed later). A directive’s job is to reactively apply side effects
to the DOM when the value of its expression changes. Let’s review the example we saw in the introduction:
v-if v-show
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
v-if vs v-show
• v-if is “real” conditional rendering because it ensures that event listeners and child components inside the
conditional block are properly destroyed and re-created during toggles.
• v-if is also lazy: if the condition is false on initial render, it will not do anything - the conditional block won’t be
rendered until the condition becomes true for the first time.
• In comparison, v-show is much simpler - the element is always rendered regardless of initial condition, with just
simple CSS-based toggling.
• Generally speaking, v-if has higher toggle costs while v-show has higher initial render costs. So prefer v-show if you
need to toggle something very often, and prefer v-if if the condition is unlikely to change at runtime.
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Arguments
Some directives can take an “argument”, denoted by a colon after the directive name. For example, the v-bind directive
is used to reactively update an HTML attribute:
Here href is the argument, which tells the v-bind directive to bind the element’s href attribute to the value of the
expression url.
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Modifiers
Modifiers are special postfixes denoted by a dot, which indicate that a directive should be bound in some special way.
For example, the .prevent modifier tells the v-on directive to call event.preventDefault() on the triggered event:
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Shorthands
The v- prefix serves as a visual cue for identifying Vue-specific attributes in your templates. This is useful when you are
using Vue.js to apply dynamic behavior to some existing markup, but can feel verbose for some frequently used
directives. At the same time, the need for the v- prefix becomes less important when you are building an SPA where
Vue.js manages every template. Therefore, Vue.js provides special shorthands for two of the most often used
directives, v-bind and v-on:
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Computed properties
In-template expressions are very convenient, but they are really only meant for simple operations. Putting too much
logic into your templates can make them bloated and hard to maintain. For example:
At this point, the template is no longer simple and declarative. That’s why for any complex logic, you should use
a computed property.
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Computed properties
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Computed caching vs Methods
You may have noticed we can achieve the same result by invoking a method in the expression:
However, the difference is that computed properties are
cached based on their dependencies. A computed
property will only re-evaluate when some of its
dependencies have changed. This means as long
as messagehas not changed, multiple access to
the reversedMessage computed property will
immediately return the previously computed result
without having to run the function again.
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Binding HTML Classes
Object Syntax
The above syntax means the presence of the active class will be
determined by the truthiness of the data property isActive.
Array Syntax
The above syntax means the presence of the active class will be
determined by the truthiness of the data property isActive.
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Binding Inline Styles
Object Syntax
The object syntax for v-bind:style is pretty straightforward - it looks almost like CSS, except it’s a JavaScript object. You
can use either camelCase or kebab-case (use quotes with kebab-case) for the CSS property names:
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Binding Inline Styles
Object Syntax
It is often a good idea to bind to a style object directly so that the template is cleaner:
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Binding Inline Styles
Auto-prefixing
When you use a CSS property that requires vendor prefixes in v-bind:style, for example transform, Vue will
automatically detect and add appropriate prefixes to the applied styles.
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
List Rendering
We can use the v-for directive to render a list of items based on an array. The v-fordirective requires a special syntax in
the form of item in items, where items is the source data array and item is an alias for the array element being iterated
on:
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
List Rendering
Inside v-for blocks we have full access to parent scope properties. v-for also supports an optional second argument for
the index of the current item.
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
v-for with an Object
You can also use v-for to iterate through the properties of an object.
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
v-for with a Range
v-for can also take an integer. In this case it will repeat the template that many times.
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
v-for with v-if
When they exist on the same node, v-for has a higher priority than v-if. That means the v-if will be run on each iteration
of the loop separately. This can be useful when you want to render nodes for only some items, like below:
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Event Handling
We can use the v-on directive to listen to DOM events and run some JavaScript when they’re triggered.
For example:
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Method Event Handlers
The logic for many event handlers will be more complex
though, so keeping your JavaScript in the value of the v-
on attribute simply isn’t feasible. That’s why v-on can also
accept the name of a method you’d like to call.
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Methods in Inline Handlers
Instead of binding directly to a method name, we can also
use methods in an inline JavaScript statement:
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Event Modifiers
It is a very common need to call event.preventDefault() or event.stopPropagation()inside event handlers. Although we
can do this easily inside methods, it would be better if the methods can be purely about data logic rather than having to
deal with DOM event details.
To address this problem, Vue provides event modifiers for v-on. Recall that modifiers are directive postfixes denoted by a
dot.
•.stop
•.prevent
•.capture
•.self
•.once
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Event Modifiers
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Key Modifiers
When listening for keyboard events, we often need to check for common key codes. Vue also allows adding key modifiers
for v-on when listening for key events:
Remembering all the keyCodes is a hassle, so Vue provides
aliases for the most commonly used keys:
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Key Modifiers
Here’s the full list of key modifier aliases:
•.enter
•.tab
•.delete (captures both “Delete” and “Backspace” keys)
•.esc
•.space
•.up
•.down
•.left
•.right
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Key Modifiers
You can also define custom key modifier aliases via the global config.keyCodes object:
<input v-on:keyup.f1="submit">
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Modifier Keys
You can use the following modifiers to trigger mouse or keyboard event listeners only when the corresponding modifier
key is pressed:
•.ctrl
•.alt
•.shift
•.meta
Note: On Macintosh keyboards, meta is the command key ( ). On Windows keyboards, meta is the windows key ( ).⌘ ⊞
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Mouse Button Modifiers
New in 2.2.0+
•.left
•.right
•.middle
These modifiers restrict the handler to events triggered by a specific mouse button.
https://jsfiddle.net/z1jhpewo/1/
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
SFC Concept (Single File Components)
• Complete syntax highlighting
• CommonJS modules
• Component-scoped CSS
• You can specify language attributes to write more specific code.
What About Separation of Concerns?
One important thing to note is that separation of concerns is not
equal to separation of file types
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Development Environment in 1 min
vue-webpack-boilerplate is the best practice to start from scratch.
Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
Credits
• https://vuejs.org/v2/guide/
• https://vuejs.org/v2/guide/single-file-components.html
• https://www.packtpub.com/mapt/book/web_development/9781786468093
• https://app.pluralsight.com/library/courses/vuejs-getting-started/table-of-contents
• https://medium.com/the-vue-point/vue-2-0-is-here-ef1f26acf4b8
• https://medium.com/unicorn-supplies/angular-vs-react-vs-vue-a-2017-comparison-
c5c52d620176
• https://medium.com/unicorn-supplies/angular-vs-react-vs-vue-a-2017-comparison-
c5c52d620176

More Related Content

PDF
ODP
An Introduction to Vuejs
PPTX
PHP Cookies and Sessions
PDF
introduction to Vue.js 3
PDF
Intro to vue.js
PDF
VueJS Introduction
PDF
JavaScript - Chapter 10 - Strings and Arrays
PDF
Spring Security
An Introduction to Vuejs
PHP Cookies and Sessions
introduction to Vue.js 3
Intro to vue.js
VueJS Introduction
JavaScript - Chapter 10 - Strings and Arrays
Spring Security

What's hot (20)

PDF
Why Vue.js?
PPTX
An introduction to Vue.js
ODP
Basics of VueJS
PDF
An introduction to Vue.js
PDF
VueJS: The Simple Revolution
PDF
The Point of Vue - Intro to Vue.js
PDF
Vue.js for beginners
PDF
Building blocks of Angular
PPTX
Vue js for beginner
PDF
Vue, vue router, vuex
PPT
Angular Introduction By Surekha Gadkari
PPTX
Express js
PPTX
React js programming concept
PDF
Laravel - The PHP Framework for Web Artisans
PPTX
Spring Boot Tutorial
PPTX
Basics of Vue.js 2019
PDF
Web Development with Laravel 5
PPTX
Spring Boot
PDF
ReactJS presentation
PDF
Spring Boot & Actuators
Why Vue.js?
An introduction to Vue.js
Basics of VueJS
An introduction to Vue.js
VueJS: The Simple Revolution
The Point of Vue - Intro to Vue.js
Vue.js for beginners
Building blocks of Angular
Vue js for beginner
Vue, vue router, vuex
Angular Introduction By Surekha Gadkari
Express js
React js programming concept
Laravel - The PHP Framework for Web Artisans
Spring Boot Tutorial
Basics of Vue.js 2019
Web Development with Laravel 5
Spring Boot
ReactJS presentation
Spring Boot & Actuators
Ad

Similar to Vue.js Getting Started (20)

PPTX
Vuejs getting-started - Extended Version
PDF
Vue JS Interview Questions By Scholarhat
PDF
The Superhero’s Method of Modern HTML5 Development by RapidValue Solutions
PDF
sveltekit-en.pdf
PPTX
Flu3nt highlights
PDF
Intro to Sails.js
PDF
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
PPT
Struts 2-overview2
PDF
Beginning AngularJS
PDF
AngularJS Beginner Day One
PDF
Knockout js session
PDF
Intelligent Projects with Maven - DevFest Istanbul
PPTX
Spring MVC framework features and concepts
PDF
Overview of the AngularJS framework
PDF
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
PDF
Testing Big in JavaScript
PDF
Full Stack React Workshop [CSSC x GDSC]
PDF
Practical WebAssembly with Apex, wasmRS, and nanobus
PDF
WordCamp Belfast DevOps for Beginners
PPTX
Vuejs getting-started - Extended Version
Vue JS Interview Questions By Scholarhat
The Superhero’s Method of Modern HTML5 Development by RapidValue Solutions
sveltekit-en.pdf
Flu3nt highlights
Intro to Sails.js
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
Struts 2-overview2
Beginning AngularJS
AngularJS Beginner Day One
Knockout js session
Intelligent Projects with Maven - DevFest Istanbul
Spring MVC framework features and concepts
Overview of the AngularJS framework
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
Testing Big in JavaScript
Full Stack React Workshop [CSSC x GDSC]
Practical WebAssembly with Apex, wasmRS, and nanobus
WordCamp Belfast DevOps for Beginners
Ad

Recently uploaded (20)

PPTX
FLIGHT TICKET RESERVATION SYSTEM | FLIGHT BOOKING ENGINE API
PPTX
AIRLINE PRICE API | FLIGHT API COST |
PDF
top salesforce developer skills in 2025.pdf
PDF
System and Network Administration Chapter 2
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PPTX
Online Work Permit System for Fast Permit Processing
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
ISO 45001 Occupational Health and Safety Management System
PPTX
Introduction to Artificial Intelligence
PDF
AI in Product Development-omnex systems
PPTX
ai tools demonstartion for schools and inter college
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Understanding Forklifts - TECH EHS Solution
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
FLIGHT TICKET RESERVATION SYSTEM | FLIGHT BOOKING ENGINE API
AIRLINE PRICE API | FLIGHT API COST |
top salesforce developer skills in 2025.pdf
System and Network Administration Chapter 2
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Materi_Pemrograman_Komputer-Looping.pptx
Online Work Permit System for Fast Permit Processing
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Materi-Enum-and-Record-Data-Type (1).pptx
Upgrade and Innovation Strategies for SAP ERP Customers
Odoo POS Development Services by CandidRoot Solutions
How to Choose the Right IT Partner for Your Business in Malaysia
ISO 45001 Occupational Health and Safety Management System
Introduction to Artificial Intelligence
AI in Product Development-omnex systems
ai tools demonstartion for schools and inter college
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Understanding Forklifts - TECH EHS Solution
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes

Vue.js Getting Started

  • 1. Vue.js Getting Started Murat Dogan – Sr. Front End Developer @ Hurriyet
  • 2. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started • What is Vue.js ? • Comparison with other libraries/frameworks • SFC Concept • Getting Started with Vue.js • Basic Vue.js Features • Creating a development environment in 1 min • Okur Temsilcisi Vue.js Edition / Vue Router
  • 3. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started
  • 4. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started How to choose the right framework? • How mature are the frameworks / libraries? • Are the frameworks likely to be around for a while? • How extensive and helpful are their corresponding communities? • How easy is it to find developers for each of the frameworks? • What are the basic programming concepts of the frameworks? • How easy is it to use the frameworks for small or large applications? • What does the learning curve look like for each framework? • What kind of performance can you expect from the frameworks? • Where can you have a closer look under the hood? • How can you start developing with the chosen framework?
  • 5. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Latest News : 11th September
  • 6. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started What is Vue.js? • Vue (pronounced /vju /, likeː view) is a progressive framework for building user interfaces.1 • It was first released in February 2014 by ex-Google-employee Evan You • Only thing you need to know is HTML, CSS and JavaScript • It’s been popular since its last version 2.0 • Vue is used by Alibaba, Baidu, Expedia, Nintendo, GitLab—a list of smaller projects can be    found on madewithvuejs.com.
  • 7. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Comparison with other libraries/frameworks Based on 3rd party benchmark, lower is better
  • 8. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Installing Vue.js •You can install core library via CDN (Content Delivery Network) •If you want to always follow up the latest version of Vue, use unpkg: • https://unpkg.com/vue - Always redirect to the latest version of Vue! • https://unpkg.com/vue@[version]/dist/vue.min.js - to specific version. •You can install core library using Bower or npm
  • 9. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Getting Started – Hello World •Open https://jsfiddle.net, choose the additional JS Framework; Vue.js •JavaScript section : • new Vue({el:'#app'}) •HTML section: • <div id="app"> {{'Hello ' + 'world'}} </div> •Result:
  • 10. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started How it works... new Vue({el:'#app'}) will instantiate a new Vue instance. It accepts an options object as a parameter. This object is central in Vue, and defines and controls data and behavior. It contains all the information needed to create Vue instances and components. In our case, we only specified the el option which accepts a selector or an element as an argument. The #app parameter is a selector that will return the element in the page with app as the identifier. For example, in a page like this: Everything that we will write inside the <div> with the ID as app will be under the scope of Vue. Now, JSFiddle takes everything we write in the HTML quadrant and wraps it in body tags. This means that if we just need to write the <div> in the HTML quadrant, JSFiddle will take care of wrapping it in the body tags.
  • 11. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started It's also important to note that placing the #app on the body or html tag will throw an error, as Vue advises us to mount our apps on normal elements, and its the same thing goes for selecting the body in the el option.
  • 12. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Lifecycle Diagram
  • 13. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Lifecycle Diagram Example
  • 14. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Interpolations Text Raw Html this will also affect any binding on the same node Attributes
  • 15. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Interpolations - JavaScript Expressions So far we’ve only been binding to simple property keys in our templates. But Vue.js actually supports the full power of JavaScript expressions inside all data bindings
  • 16. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Directives Directives are special attributes with the v- prefix. Directive attribute values are expected to be a single JavaScript expression (with the exception for v-for, which will be discussed later). A directive’s job is to reactively apply side effects to the DOM when the value of its expression changes. Let’s review the example we saw in the introduction: v-if v-show
  • 17. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started v-if vs v-show • v-if is “real” conditional rendering because it ensures that event listeners and child components inside the conditional block are properly destroyed and re-created during toggles. • v-if is also lazy: if the condition is false on initial render, it will not do anything - the conditional block won’t be rendered until the condition becomes true for the first time. • In comparison, v-show is much simpler - the element is always rendered regardless of initial condition, with just simple CSS-based toggling. • Generally speaking, v-if has higher toggle costs while v-show has higher initial render costs. So prefer v-show if you need to toggle something very often, and prefer v-if if the condition is unlikely to change at runtime.
  • 18. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Arguments Some directives can take an “argument”, denoted by a colon after the directive name. For example, the v-bind directive is used to reactively update an HTML attribute: Here href is the argument, which tells the v-bind directive to bind the element’s href attribute to the value of the expression url.
  • 19. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Modifiers Modifiers are special postfixes denoted by a dot, which indicate that a directive should be bound in some special way. For example, the .prevent modifier tells the v-on directive to call event.preventDefault() on the triggered event:
  • 20. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Shorthands The v- prefix serves as a visual cue for identifying Vue-specific attributes in your templates. This is useful when you are using Vue.js to apply dynamic behavior to some existing markup, but can feel verbose for some frequently used directives. At the same time, the need for the v- prefix becomes less important when you are building an SPA where Vue.js manages every template. Therefore, Vue.js provides special shorthands for two of the most often used directives, v-bind and v-on:
  • 21. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Computed properties In-template expressions are very convenient, but they are really only meant for simple operations. Putting too much logic into your templates can make them bloated and hard to maintain. For example: At this point, the template is no longer simple and declarative. That’s why for any complex logic, you should use a computed property.
  • 22. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Computed properties
  • 23. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Computed caching vs Methods You may have noticed we can achieve the same result by invoking a method in the expression: However, the difference is that computed properties are cached based on their dependencies. A computed property will only re-evaluate when some of its dependencies have changed. This means as long as messagehas not changed, multiple access to the reversedMessage computed property will immediately return the previously computed result without having to run the function again.
  • 24. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Binding HTML Classes Object Syntax The above syntax means the presence of the active class will be determined by the truthiness of the data property isActive. Array Syntax The above syntax means the presence of the active class will be determined by the truthiness of the data property isActive.
  • 25. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Binding Inline Styles Object Syntax The object syntax for v-bind:style is pretty straightforward - it looks almost like CSS, except it’s a JavaScript object. You can use either camelCase or kebab-case (use quotes with kebab-case) for the CSS property names:
  • 26. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Binding Inline Styles Object Syntax It is often a good idea to bind to a style object directly so that the template is cleaner:
  • 27. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Binding Inline Styles Auto-prefixing When you use a CSS property that requires vendor prefixes in v-bind:style, for example transform, Vue will automatically detect and add appropriate prefixes to the applied styles.
  • 28. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started List Rendering We can use the v-for directive to render a list of items based on an array. The v-fordirective requires a special syntax in the form of item in items, where items is the source data array and item is an alias for the array element being iterated on:
  • 29. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started List Rendering Inside v-for blocks we have full access to parent scope properties. v-for also supports an optional second argument for the index of the current item.
  • 30. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started v-for with an Object You can also use v-for to iterate through the properties of an object.
  • 31. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started v-for with a Range v-for can also take an integer. In this case it will repeat the template that many times.
  • 32. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started v-for with v-if When they exist on the same node, v-for has a higher priority than v-if. That means the v-if will be run on each iteration of the loop separately. This can be useful when you want to render nodes for only some items, like below:
  • 33. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Event Handling We can use the v-on directive to listen to DOM events and run some JavaScript when they’re triggered. For example:
  • 34. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Method Event Handlers The logic for many event handlers will be more complex though, so keeping your JavaScript in the value of the v- on attribute simply isn’t feasible. That’s why v-on can also accept the name of a method you’d like to call.
  • 35. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Methods in Inline Handlers Instead of binding directly to a method name, we can also use methods in an inline JavaScript statement:
  • 36. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Event Modifiers It is a very common need to call event.preventDefault() or event.stopPropagation()inside event handlers. Although we can do this easily inside methods, it would be better if the methods can be purely about data logic rather than having to deal with DOM event details. To address this problem, Vue provides event modifiers for v-on. Recall that modifiers are directive postfixes denoted by a dot. •.stop •.prevent •.capture •.self •.once
  • 37. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Event Modifiers
  • 38. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Key Modifiers When listening for keyboard events, we often need to check for common key codes. Vue also allows adding key modifiers for v-on when listening for key events: Remembering all the keyCodes is a hassle, so Vue provides aliases for the most commonly used keys:
  • 39. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Key Modifiers Here’s the full list of key modifier aliases: •.enter •.tab •.delete (captures both “Delete” and “Backspace” keys) •.esc •.space •.up •.down •.left •.right
  • 40. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Key Modifiers You can also define custom key modifier aliases via the global config.keyCodes object: <input v-on:keyup.f1="submit">
  • 41. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Modifier Keys You can use the following modifiers to trigger mouse or keyboard event listeners only when the corresponding modifier key is pressed: •.ctrl •.alt •.shift •.meta Note: On Macintosh keyboards, meta is the command key ( ). On Windows keyboards, meta is the windows key ( ).⌘ ⊞
  • 42. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Mouse Button Modifiers New in 2.2.0+ •.left •.right •.middle These modifiers restrict the handler to events triggered by a specific mouse button. https://jsfiddle.net/z1jhpewo/1/
  • 43. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started SFC Concept (Single File Components) • Complete syntax highlighting • CommonJS modules • Component-scoped CSS • You can specify language attributes to write more specific code. What About Separation of Concerns? One important thing to note is that separation of concerns is not equal to separation of file types
  • 44. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Development Environment in 1 min vue-webpack-boilerplate is the best practice to start from scratch.
  • 45. Murat Dogan – Sr. Front End Developer @ HurriyetVue.js – Getting Started Credits • https://vuejs.org/v2/guide/ • https://vuejs.org/v2/guide/single-file-components.html • https://www.packtpub.com/mapt/book/web_development/9781786468093 • https://app.pluralsight.com/library/courses/vuejs-getting-started/table-of-contents • https://medium.com/the-vue-point/vue-2-0-is-here-ef1f26acf4b8 • https://medium.com/unicorn-supplies/angular-vs-react-vs-vue-a-2017-comparison- c5c52d620176 • https://medium.com/unicorn-supplies/angular-vs-react-vs-vue-a-2017-comparison- c5c52d620176