Thorsten Lünborg
github.com/linusborg // @linus_borg
Vue (pronounced /vjuː/, like view) is a progressive framework for building user interfaces.
Vue is focused on the view layer only and it can be used as a library in any project. At the same time, it can be a full-blown framework, perfectly capable of building complex Single Page Applications.
93,737 GitHub Stars
Top 10 All-Time
2nd most-starred JavaScript framework
>20 Core Team members,
many contributors
Opposed to imperative code that we would write with jQuery and similar tools
const items = [
'thingie',
'another thingie',
'lots of stuff',
'yadda yadda'
];
function listOfStuff() {
let full_list = '';
for (let i = 0; i < items.length; i++) {
full_list = full_list + `<li> ${items[i]} </li>`
}
const contain = document.querySelector('#container');
contain.innerHTML = `<ul> ${full_list} </ul>`;
}
listOfStuff();
<div id="app">
<ul>
<li v-for="item in items">
{{ item }}
</li>
</ul>
</div>
<script>
new Vue({
el: '#app',
data: {
items: [
'thingie',
'another thingie',
'lots of stuff',
'yadda yadda'
]
}
});
</script>
<div id="app">
<h3>Type here:</h3>
<textarea v-model="message"></textarea><br>
<p class="booktext">{{ message }} </p>
</div>
<script>
new Vue({
el: '#app',
data() {
return {
message: 'This is a good place to type things.'
}
}
});
</script>
<div id="app">
<h3>Type here:</h3>
<input v-model="firstName"></input><br>
<input v-model="lastName"></input><br>
<p class="booktext">{{ fullName }} </p>
</div>
<script>
new Vue({
el: '#app',
data() {
return {
firstName: 'Tom',
lastName: 'Thompson',
}
},
computed: {
fullName() {
return `${this.firstName} ${this.lastName}`
}
}
});
</script>
<div id="app">
<h3>Type here:</h3>
<p v-if="showParagraph">
The visibility of this paragraph can be toggled
With the button below
</p>
<button v-on:click="toggle">
Toggle
</button>
</div>
<script>
new Vue({
el: '#app',
data() {
return {
showParagraph: true
}
},
methods: {
toggle() {
this.showParagraph = !this.showParagraph
}
}
});
</script>
<div id="app">
<h3>Type here:</h3>
<p v-if="showParagraph">
The visibility of this paragraph can be toggled
With the button below
</p>
<button v-on:click="toggle">
Toggle
</button>
</div>
<script>
new Vue({
el: '#app',
data() {
return {
showParagraph: true
}
},
methods: {
toggle() {
this.showParagraph = !this.showParagraph
}
}
});
</script>
<header></header>
<aside>
<sidebar-item v-for="item in items"></sidebar-item>
</aside>
<main>
<blogpost v-for="post in posts"></blogpost>
</main>
<footer></footer>
<div id="app">
<child v-bind:text="message"></child>
</div>
<script>
Vue.component('child', {
props: ['text'],
template: `<div>{{ text }}<div>`
});
new Vue({
el: "#app",
data() {
return {
message: 'hello mr. magoo'
}
}
});
</script>
<div id="app">
<child v-on:clicked="handleClick"></child>
</div>
<script>
Vue.component('child', {
props: ['text'],
template: `<button v-on:click="$emit('clicked!')">Click me!</button>`
});
new Vue({
el: "#app",
method: {
handleClick() {
//
}
}
});
</script>
Props down
Events up
<div id="app">
<child>
<p>
This is the
<strong>Slot Content</strong>
</p>
</child>
</div>
<script>
Vue.component('child', {
template: `<div> <slot /> <div>`
});
new Vue({
el: "#app",
});
</script>
<!-- Result -->
<div id="app">
<div class="child">
<p>
This is the
<strong>Slot Content</strong>
</p>
</div>
</div>
"A nice little toy"
"looks a little like angular, yikes!"
"Can I build applications with this?"
v3 in beta!
v1 in beta!
(SFCs)
<template>
<div class="red">{{ text }}<div>
</template>
<script>
export default {
props: ['text'],
methods: {
// ..
}
}
</script>
<style>
.red {
color: red;
}
</style>
What many call "seperation of concerns"
We call: "Seperation of technologies".
Your component is made up of Markup, code, and styling, and you rarely find yourself concerned about only one.
So your concern is mostly about all three, they belong together
now, or visit me at the forum later: