06.06.2018
Vue.js
syntax
components (SFC)
vuex
vue-cli
live coding
Nuxt.js
VuePress
small
blazing fast
just javascript
easy to setup
cool errors
(~58.8K)
const app = new Vue({
el: '#app',
data: {
msg: 'I am Vue'
}
})
<div id="app">{{ msg }}</div>
https://unpkg.com/vue@2.5.16/dist/vue.js
<div>{{ msg }}</div>
<div v-text="msg"></div>
<div v-html="msg"></div>
<div v-once>{{ msg }}</div>
<div v-if="show">{{ msg }}</div>
<div v-else>No message</div>
<div v-show="show">must go on</div>
const app = new Vue({
el: '#app',
data: {
show: true,
msg: 'Hello'
}
})
<div v-for="movie in movies">{{movie.title}}</div>
const app = new Vue({
el: '#app',
data: {
movies: [
{ title: 'Matrix' },
{ title: 'Julie & Romeo' }
]
}
})
<div :class="{active: isActive}"></div>
<div :style="{color: activeColor}"></div>
const app = new Vue({
el: '#app',
data: {
active: true,
activeColor: 'black'
}
})
<button v-on:click="doMagic">
<button @click="doMagic">
<button @click.stop="doMagic">
<button @click.stop.prevent="doMagic">
<button @click="doMagic(movie)">
<button @click="doMagic($event, movie)">
const app = new Vue({
el: '#app',
methods: {
function doMagic(e){},
doMagic(e, movie){}
}
})
<div>{{ rate | currency }}</div>
<div>{{ rate | currency('USD') }}</div>
<div>{{ rate | format | currency('USD') }}</div>
Vue.filter("currency", s => {
return `${s} CZK`;
});
<div id="app">
<hello></hello>
</div>
Vue.component('hello', {
template: '<p>Hello world</p>'
})
const app = new Vue({
el: '#app'
})
<template>
<p>{{ greeting }} World!</p>
</template>
<script>
module.exports = {
data: function () {
return {
greeting: 'Hello'
}
}
}
</script>
<style scoped>
p {
font-size: 2em;
text-align: center;
}
</style>
const store = new Vuex.Store({
state: {
clicks: 0
},
mutations: {
increaseClicks(state) {
state.clicks++;
}
}
})
store.commit('increaseClicks');
store.state.clicks // -> 1
const store = new Vuex.Store({
state: {
clicks: 0
},
mutations: {
increaseClicks(state) {
state.clicks++;
}
}
})
const app = new Vue({
el: '#app',
store: store,
computed: {
clicks() {
return this.$store.state.clicks;
}
},
methods: {
onBtnClick() {
this.$store.commit('increaseClicks');
}
}
})
<div id="app">
Total clicks: {{clicks}}
<button @click="onBtnClick">CLICK ME</button>
</div>
vue init webpack-simple my-project
https://codesandbox.io/s/p5jl7qplvq
https://github.com/trainit/2018-06-vue-nuxt-vuepress