Vue.js przebojem zdobywa popularność w środowisku frontendowym. W wielu ofertach pracy możesz spotkać się z nim jako z jednym z sugerowanych frameworków. Zdecydowanie warto poświęcić mu swoją uwagę, ponieważ łatwo się go nauczyć, a może on otworzyć Tobie bramy do pracy jako developer w niejednej firmie.
Nasz zespół, jako jeden z pionierów Vue.js w Polsce, na co dzień wykorzystuje tę technologię w wielu projektach komercyjnych. Znasz podstawy HTMLa, CSSa i JavaScriptu? Może na studiach miałeś okazję bawić się jQuery? To wystarczy, by zacząć swoją przygodę z Vue.js.
W trakcie prezentacji opowiemy Wam o komponentach - wzorcu na którym opierają się wszystkie nowoczesne frameworki frontendowe. Dowiecie się o również o tym, do czego służą dyrektywy, metody, computed properties i eventy w Vue.js oraz jak z nich korzystać. Stworzymy małą aplikację, aby pokazać Wam jak można zrobić to samemu od A do Z.
20. Let’s become a Vue.js developer!
index.vue
<template>
<div>
<h1>
Click below to become a Vue.js developer.
</h1>
<button>
Become a Vue.js developer
</button>
</div>
</template>
...
<style>
h1 {
font-family: "Helvetica";
color: #41b883;
}
</style>
21.
22. Let’s become a Vue.js developer!
index.vue
<template>
<div>
<h1>
Congratulations, you’re a Vue.js developer!
</h1>
<h1>
Click below to become a Vue.js developer.
</h1>
<button>
Become a Vue.js developer
</button>
</div>
</template>
...
<style>
h1 {
font-family: "Helvetica";
color: #41b883;
}
</style>
23.
24. Let’s become a Vue.js developer!
index.vue
<template>
<div>
<h1>
Congratulations, you are a Vue.js developer!
</h1>
<h1>
Click below to become a Vue.js developer.
</h1>
<button>
Become a Vue.js developer
</button>
</div>
</template>
<script>
export default {
data () {
return {
isVueDeveloper: false
}
}
}
</script>
25. Let’s become a Vue.js developer!
index.vue
<template>
<div>
<h1 v-if="isVueDeveloper">
Congratulations, you are a Vue.js developer!
</h1>
<h1>
Click below to become a Vue.js developer.
</h1>
<button>
Become a Vue.js developer
</button>
</div>
</template>
<script>
export default {
data () {
return {
isVueDeveloper: false
}
}
}
</script>
27. Let’s become a Vue.js developer!
index.vue
<template>
<div>
<h1 v-if="isVueDeveloper">
Congratulations, you are a Vue.js developer!
</h1>
<h1 v-if="!isVueDeveloper">
Click below to become a Vue.js developer.
</h1>
<button>
Become a Vue.js developer
</button>
</div>
</template>
<script>
export default {
data () {
return {
isVueDeveloper: false
}
}
}
</script>
29. Let’s become a Vue.js developer!
index.vue
<template>
<div>
<h1 v-if="isVueDeveloper">
Congratulations, you are a Vue.js developer!
</h1>
<h1 v-if="!isVueDeveloper">
Click below to become a Vue.js developer.
</h1>
<button @click="isVueDeveloper = true">
Become a Vue.js developer
</button>
</div>
</template>
<script>
export default {
data () {
return {
isVueDeveloper: false
}
}
}
</script>
30. Let’s become a Vue.js developer!
index.vue
<template>
<div>
<h1 v-if="isVueDeveloper">
Congratulations, you are a Vue.js developer!
</h1>
<h1 v-else>
Click below to become a Vue.js developer.
</h1>
<button @click="isVueDeveloper = true">
Become a Vue.js developer
</button>
</div>
</template>
<script>
export default {
data () {
return {
isVueDeveloper: false
}
}
}
</script>
31. Let’s become a Vue.js developer!
index.vue
<template>
<div>
<h1 v-if="isVueDeveloper">
Congratulations, you are a Vue.js developer!
</h1>
<h1 v-else>
Click below to become a Vue.js developer.
</h1>
<button @click="becomeVueDeveloper">
Become a Vue.js developer
</button>
</div>
</template>
<script>
export default {
data () {
return {
isVueDeveloper: false
}
},
methods: {
becomeVueDeveloper () {
this.isVueDeveloper = true
}
}
}
</script>
33. Let’s become a better Vue.js developer!
index.vue
<template>
<div>
<h1>
Click 5 times to become a better Vue.js developer.
</h1>
<button>
Become a better Vue.js developer
</button>
</div>
</template>
...
<style>
h1 {
font-family: "Helvetica";
color: #41b883;
}
</style>
34.
35. Let’s become a better Vue.js developer!
index.vue
<template>
<div>
<h1>
Click {{ clicksLeft }} times to become
a better Vue.js developer.
</h1>
<button>
Become a better Vue.js developer
</button>
</div>
</template>
...
<script>
export default {
data () {
return {
clicksLeft: 5
}
}
}
</script>
36.
37. Let’s become a better Vue.js developer!
index.vue
<template>
<div>
<h1>
Click {{ clicksLeft }} times to become
a better Vue.js developer.
</h1>
<button @click="decrementClicks">
Become a better Vue.js developer
</button>
</div>
</template>
<script>
export default {
data () {
return {
clicksLeft: 5
}
},
methods: {
decrementClicks () {
this.clicksLeft -= 1
}
}
}
</script>
38.
39.
40. Let’s become a better Vue.js developer!
index.vue
<template>
<div>
<h1>
Click {{ clicksLeft }} times to become
a better Vue.js developer.
</h1>
<button @click="decrementClicks">
Become a better Vue.js developer
</button>
</div>
</template>
<script>
export default {
data () {
return {
clicksLeft: 5
}
},
methods: {
decrementClicks () {
if (this.clicksLeft > 0) {
this.clicksLeft -= 1
}
}
}
}
</script>
41.
42.
43. Let’s become a better Vue.js developer!
index.vue
<template>
<div>
<h1 v-if="clicksLeft === 0">
Congratulations, you are a better Vue.js developer!
</h1>
<h1 v-else>
Click {{ clicksLeft }} times to become
a better Vue.js developer.
</h1>
<button @click="decrementClicks">
Become a better Vue.js developer
</button>
</div>
</template>
<script>
export default {
data () {
return {
clicksLeft: 5
}
},
methods: {
decrementClicks () {
if (this.clicksLeft > 0) {
this.clicksLeft -= 1
}
}
}
}
</script>
44.
45.
46. Looks familiar…
Before
<template>
<div>
<h1 v-if="isVueDeveloper">
Congratulations, you are a Vue.js developer!
</h1>
<h1 v-else>
Click below to become a Vue.js developer.
</h1>
<button @click="becomeVueDeveloper">
Become a Vue.js developer
</button>
</div>
</template>
Now
<template>
<div>
<h1 v-if="clicksLeft === 0">
Congratulations, you are a better
Vue.js developer!
</h1>
<h1 v-else>
Click {{ clicksLeft }} times to become
a better Vue.js developer.
</h1>
<button @click="decrementClicks">
Become a better Vue.js developer
</button>
</div>
</template>
47. Let’s become a better Vue.js developer!
index.vue
<template>
<div>
<h1 v-if="isBetterVueDeveloper">
Congratulations, you are a better
Vue.js developer!
</h1>
<h1 v-else>
Click {{ clicksLeft }} times to become
a better Vue.js developer.
</h1>
<button @click="decrementClicks">
Become a better Vue.js developer
</button>
</div>
</template>
<script>
export default {
data () {
return {
clicksLeft: 5
}
},
computed: {
isBetterVueDeveloper () {
return this.clicksLeft === 0
}
},
methods: {
decrementClicks () {
if (this.clicksLeft > 0) {
this.clicksLeft -= 1
}
}
}
}
</script>
48. What vs How?
Declarative (yay!)
● what should be shown
● what data means
● what happens on interaction
Imperative (nay)
● how should be rendered
● how data is computed
● how to update after changes
WHAT HOW
49. Let’s become a super Vue.js developer!
index.vue
<template>
<div>
<h1>
Check all things below to become a super Vue.js developer 0/4
</h1>
<ul>
<li><input type="checkbox"> knows v-if & v-else</li>
<li><input type="checkbox"> knows methods & computed</li>
<li><input type="checkbox"> knows v-model</li>
<li><input type="checkbox"> knows v-for</li>
</ul>
</div>
</template>
<style>
h1 {
font-family: "Helvetica";
color: #41b883;
}
li {
list-style: none;
font-size: 30px;
}
input[type="checkbox"] {
width: 20px;
height: 20px;
}
</style>
50. Let’s become a super Vue.js developer!
index.vue
<template>
<div>
<h1>
Check all things below to become a super
Vue.js developer {{ checkedCount }}/4
</h1>
<ul>
<li>
<input type="checkbox" v-model="isChecked">
knows v-if & v-else
</li>
</ul>
</div>
</template>
<script>
export default {
data () {
return {
isChecked: false
}
},
computed: {
checkedCount () {
if (this.isChecked) return 1
return 0
}
}
}
</script>
51. Let’s become a super Vue.js developer!
index.vue
<template>
<div>
<h1>
Check all things below to become a super Vue.js developer
{{ checkedCount }}/4
</h1>
<ul>
<li>
<input type="checkbox" v-model="isChecked1"> knows v-if & v-else
</li>
<li>
<input type="checkbox" v-model="isChecked2"> knows methods & computed
</li>
<li>
<input type="checkbox" v-model="isChecked3"> knows v-model
</li>
<li>
<input type="checkbox" v-model="isChecked4"> knows v-for
</li>
</ul>
</div>
</template>
<script>
export default {
data () {
return {
isChecked1: false,
isChecked2: false,
isChecked3: false,
isChecked4: false
}
},
computed: {
checkedCount () {
// A lot of ifs...
}
}
}
</script>
59. Let’s become a super Vue.js developer!
index.vue
<template>
<div>
<h1 v-if="isSuperVueDeveloper">
Congratulations, you are a super Vue.js developer!
</h1>
<template v-else>
<h1>
Check all things below to become a super Vue.js developer
{{ checkedCount }}/{{ items.length }}
</h1>
<ul>
<li v-for="item in items" :key="item.description">
<input type="checkbox" v-model="item.isChecked">
{{ item.description }}
</li>
</ul>
</template>
</div>
</template>
60. All together now!!!
first-challenge.vue
<template>
<div>
<h1 v-if="isVueDeveloper">
Congratulations, you are a Vue.js developer!
...
second-challenge.vue
<template>
<div>
<h1 v-if="isBetterVueDeveloper">
Congratulations, you are a better Vue.js developer!
...
third-challenge.vue
<template>
<div>
<h1 v-if="isSuperVueDeveloper">
Congratulations, you are a super Vue.js developer!
...
<template>
<main>
<FirstChallenge />
<hr />
<SecondChallenge />
<hr />
<ThirdChallenge />
</main>
</template>
<script>
import FirstChallenge from './first-challenge'
import SecondChallenge from './second-challenge'
import ThirdChallenge from './third-challenge'
export default {
components: {
FirstChallenge,
SecondChallenge,
ThirdChallenge
}
}
</script>
index.vue
61. What we learned
Vue.js
● data binding
● v-if, v-else
● methods
● computed
● v-model
● v-for, :key
Front-end
● components
● declarative style
● DRY
62. What’s yet to learn
● communication between components
● routing
● scoped styles
● transitions
● dynamic styles
● Pug, SCSS/Sass/Stylus/PostCSS
● ... everything else!