Berlin 23 Nov 2018
Vue core team
Vue.js Meetup Paris
Remote Freelance Developer
📚 Directly on the guide
<NavBar>
<Logo/>
<NavBarUser v-if="isLoggedIn">
{{ username }}</NavBarUser>
<NavBarGroup v-else>
<NavBarButton>Create an account</NavBarButton>
<NavBarButton>Login</NavBarButton>
</NavBarGroup>
</NavBar>
(<NavBar>
<Logo />
{this.isLoggedIn ? (
<NavBarUser>{this.username}</NavBarUser>
) : (
<NavBarGroup>
<NavBarButton>Create an account</NavBarButton>
<NavBarButton>Login</NavBarButton>
</NavBarGroup>
)}
</NavBar>)
function render() {
with (this) {
return _c(
'NavBar',
[
_c('Logo'),
isLoggedIn
? _c('NavBarUser', [_v(_s(username))])
: _c(
'NavBarGroup',
[_c('NavBarButton', [_v('Create an account')]), _c('NavBarButton', [_v('Login')])],
1
),
],
1
);
}
}
Modify the state as usual and watch the HTML automatically update
const vm = new Vue({
// some options
})
vm.username = 'Jocelyn'
vm.messages.push({
text: 'Yo!',
author: 'Romeo'
})
Declarative rendering
Component System
Client-side
Routing
State Management
Build system
aka
webpack + babel
⚡️ Delightful web development
by @egoist
Big chunks of HTML toggled with v-if? 🤔
<div id="app">
<div class="part1" v-if="condition">...</div>
<div class="part2" v-else-if="condition2">...</div>
<div class="part3" v-else-if="condition3">...</div>
<div class="part4" v-else-if="condition4">...</div>
...
<div class="part10" v-else>...</div>
</div>
Using dynamic components
<div id="app">
<a v-on:click="currentView = 'Home'"
>Home</a>
<a v-on:click="currentView = 'About'"
>About</a>
<component v-bind:is="currentView"/>
</div>
Vue.component('Home', Home)
Vue.component('About', About)
new Vue({
el: '#app',
data: {
currentView: 'Home'
}
})
import Home from './views/Home'
import About from './views/About'
const routes = {
'/': Home,
'/about': About
}
new Vue({
el: '#app',
data: {
currentRoute: window.location.pathname
},
computed: {
ViewComponent() {
return routes[this.currentRoute] || NotFound
}
},
methods: {
goTo(path) {
this.currentRoute = path
window.history.pushState({}, '', path)
}
},
})
new Vue({
// other options
mounted() {
window.addEventListener('popstate', () => {
this.currentRoute = window.location.pathname
})
}
})
const routes = {
'/': () => import('./views/Home'),
'/about': () => import('./views/About')
}
<div id="app">
<a href="/" v-on:click.prevent="goTo('/')">/</a>
<a href="/about" v-on:click.prevent="goTo('/about')">/about</a>
<component v-bind:is="ViewComponent" />
</div>
Vue.prototype.$goTo = function (path) {
window.history.pushState({}, '', path)
}
$root
const vm = new Vue({
// other options
data: {
user: null,
locale: 'en'
}
})
// inside of a component
this.$root === vm
this.$root.user = { name: 'Jonathan' }
Object.defineProperty(Vue.prototype, '$state', {
get () { return this.$root.$data }
})
// inside of a component
this.$state.user = {
name: 'Jonathan'
}
Vue.prototype.login = async function (user, password) {
this.$state.user =
await authService.login(user, password)
localStorage.setItem('user', this.$state.user)
})
new Vue({
// other options
created () {
this.$state.user = localStorage.getItem('user')
}
})
const sourceOfTruth = { name: 'Joseph' }
const vmA = new Vue({
data: sourceOfTruth
})
const vmB = new Vue({
data: sourceOfTruth
})
const vmC = new Vue({
data: {
// other data
sourceOfTruth
}
})
vmA.name = 'Josuke'
vmB.sourceOfTruth.name =
'Giorno'
Follow your gut 💛
Why? 🤔
When? ⏳
Actions
View
State
+450 contributors