SlideShare une entreprise Scribd logo
1  sur  30
Vue 2.0
+
Vue Router & Vuex
Indie Inc. Co-founder & CTO
Takuya Tejima
Who
• Takuya Tejima @tejitak
• Co-founder & CTO at Indie Inc.
• Server & Web Front-end, iOS Engineer
• DevMorning community founder
• http://devmorning.connpass.com/
• Vue.js core team member
Vue.js MeetUp Tokyo!
• 2016/5/31
• Vue.js Tokyo v-meetup="#1"
• http://vuejs-
meetup.connpass.com/event/31139/
• Evan creator of Vue.js joined via Skype!
• He said “Vue.js is for everyone, not
for a company”
What is Vue.js
Vue Component Example
<template>
<div id="app">
<img src="./assets/logo.png">
<h1>{{ msg }}</h1>
</div>
</template>
<script>
export default {
data () {
return {
msg: 'Hello Vue 2.0!'
}
}
}
</script>
<style>
body {
font-family: Helvetica, sans-serif;
}
</style>
Example of App.vue with webpack https://github.com/vuejs-templates/webpack-simple-2.0
Vue.js 2.0
Our JavaScript framework is
faster than React
rendering speed and memory consumption by up to 2-4x in m
ww.infoworld.com/article/3063615/javascript/vuejs-lead-our-javascript-framework-is-faster-than-re
Vue 2.0 Features
• Fast!
• Rendering layer is based on Snabbdom (a lightweight virtual-DOM implementation)
https://github.com/paldepind/snabbdom
• Compiler & Runtime are now separated
• Reactive!
• No need for shouldComponentUpdate / immutable
• Template ? JSX?
• You can use both with original template & new render function
• Sever Side Rendering! (Streaming SSR)
• NativeRendering
• Compatibility with v1.0
Vue 2.0 API Changes
• Lots of APIs are deprecated https://github.com/vuejs/vue/issues/2873
• Filter! (e.g. <span v-text="message | reverse"></span>)
• only available in text interpolations {{}}
• no build-in filters
• vm.$dispatch -> Vuex event bus
• vm.$appendTo -> Just use native DOM API
• v-for $index & $key -> (value, index) in arr, (value, key) in obj
• etc.
Rendering Implementations
• https://speakerdeck.com/kazupon/next-vue-dot-js-2-dot-0
Vue Router
Popular Frameworks for SPA Implementation
• How to implement a SPA (Single-page Application)
• Backbone, Ember, Riot, Angular + ui-router, Angular2, React +
React-Router (+ Redux), Vue.js + Vue-Router (+ Vuex)
• Important things to introduce
• Does your app really need to be a SPA?
• For example, do you need partial rendering?
• Choose framework depending on your app characteristics
What’s Vue-Router
• Creating a SPA with Vue.js + vue-router is dead simple
• Not only client-side routing (hash / history API), but also module based URL mapping
• Nested routes and sub components
• Async load
• etc.
• The following hooks are available
• data, activate, deactivate, canActivate, canDeactivate, canReuse
• NOTE The hooks will be changed to onEnter, onLeave, onChange in Vue-Router v0.8.0
• https://github.com/vuejs/vue-router/issues/321
Nested Routes and Sub Components & Hooks
Example URL change: /a/b/c -> /a/d/e
2. Validation phase
Check if all current components can be
activated / deactivated
3. Activation phase
Deactivate current components and activate new
components with data hook
1. Reusability phase
Check reusability
Code Example
main.vue
router.map({
'/about': {
component: require('./components/about.vue')
},
'/user/:userId': {
component: require('./components/user/index.vue'),
subRoutes: {
'profile/:something': {
component: require('./components/user/profile.vue')
}
},
'*': {
component: require('./components/not-found.vue')
},
})
app.vue
<template>
<div>
<p v-show="authenticating" style="color:red">Authenticating...</p>
<h1>App Header</h1>
<a v-link="{ path: '/about' }">about</a>
<a v-link="{ path: '/user/1234/profile/what' }">user</a>
<a v-link="{ path: '/mypage' }">mypage</a>
<router-view class="view" transition="test" transition-mode="out-in" keep-
alive></router-view>
</div>
</template>
components/user/index.vue
<template>
<div>
<h2>User yo</h2>
<router-view></router-view>
</div>
</template>
components/user/profile.vue
Authentication
router.beforeEach((transition) => {
if (transition.to.path === '/mypage') {
router.app.authenticating = true
// check if the user is authenticated
api.checkAuth().then(() => {
router.app.authenticating = false
// authentication success
transition.next()
}).catch(() => {
router.app.authenticating = false
// authentication failed
transition.abort()
})
} else {
transition.next()
}
})
Example auth page implementation with global before hook
Is Vue-Router Enough?
• If your SPA with Vue-Router has complex component state
structures, Vuex could be a solution
• Basically, more communications (e.g. dispatch &
broadcast) between components leads to unreadable
code
Vuex
Vuex
• Official redux inspired flux framework for Vue.js
• Vuex is more fit for Vue.js with efficient reactive system such as
data reactive rendering & components systems
Vuex
• Features
• Store
• basically a container that holds your application reactive states
• only way to change a store's state is by explicitly dispatching mutations
• Mutation
• sync (can not be async)
• split into modules with corresponding slice of the state
• Action
• dispatch mutations
• can be async
• Advantages
• simple unidirectional flow (less side effects)
• easy undo/redo - time travel
• hot reloading
• easy test
Vuex Flow Summary with Counter Example
Mutation Example
• Mutation (a name and a handler) mutates states with synchronous functions
• Vuex store's state is made reactive by Vue
• When we mutate the state, Vue components observing the state will update
automatically
import Vuex from 'vuex'
const store = new Vuex.Store({
state: {
count: 1
},
mutations: {
INCREMENT (state) {
// mutate state
state.count++
}
}
})
store.dispatch('INCREMENT')
• Must be called by dispatch in Action
What’s a Getter
• A getter provides accessing way to store data from components
• Components are not allowed to directly mutate a state
• It allows us to reuse computed methods (e.g. totals, averages) through a getter
- Getter Example
// getters.js
export function filteredMessages (state) {
return state.messages.filter(message => message.threadID === state.currentThreadID)
}
- Component
<script>
export default {
vuex: {
getters: {
filteredMessages
}
}
}
</script>
<template>
<div>
<ul>
<li v-for="msg in filteredMessages">{{mgs.title}}</li>
</ul>
</div>
</template>
NOTE the design may changed at Vuex 2.0
https://github.com/vuejs/vuex/issues/236
Vuex Form Handling
v-model directly rewrites store data. This is not the Vuex way (throws an error in strict
mode)
The Vuex way with v-model
- Set a getter value to form value
- Dispatch action by UI event (e.g. onclick)
Template:
<input :value="message" @input=“updateMessage”>
JS:
actions: {
updateMessage: ({ dispatch }, e) => {
dispatch('UPDATE_MESSAGE', e.target.value)
}
}
Dev Tools
https://github.com/vuejs/vue-devtools
Vue-Router + Vuex
Vue-router-sync
• Vue Router x Vuex
• Inject (sync) router states to Vuex states
• Components can access router data (path,
params, query) through vuex getter in components
router
• https://github.com/vuejs/vuex-router-sync
SPA with Awesome Vue Family
• If your application is not SPA just use Vue.js
• If your SPA …
• Needs mapping URL for components / partial rendering -> Vue Router
• Needs complex component state structure -> Vuex
• Needs both above -> Vuex + Vue Router + Vue Router Sync
Join Vue.js Community
• Vuejs-jp Skack
• https://vuejs-jp-slackin.herokuapp.com/
• Translations
• Vex docs are working in progress
• https://github.com/vuejs/vuex/pull/240
Thanks

Contenu connexe

Tendances

Vue.js Getting Started
Vue.js Getting StartedVue.js Getting Started
Vue.js Getting StartedMurat Doğan
 
Vue.js
Vue.jsVue.js
Vue.jsBADR
 
How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0Takuya Tejima
 
Vue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue routerVue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue routerKaty Slemon
 
Vue js 大型專案架構
Vue js 大型專案架構Vue js 大型專案架構
Vue js 大型專案架構Hina Chen
 
Javascript MVVM with Vue.JS
Javascript MVVM with Vue.JSJavascript MVVM with Vue.JS
Javascript MVVM with Vue.JSEueung Mulyana
 
Scalable Front-end Development with Vue.JS
Scalable Front-end Development with Vue.JSScalable Front-end Development with Vue.JS
Scalable Front-end Development with Vue.JSGalih Pratama
 
introduction to Vue.js 3
introduction to Vue.js 3 introduction to Vue.js 3
introduction to Vue.js 3 ArezooKmn
 
Enjoy the vue.js
Enjoy the vue.jsEnjoy the vue.js
Enjoy the vue.jsTechExeter
 
VueJS Introduction
VueJS IntroductionVueJS Introduction
VueJS IntroductionDavid Ličen
 
Vue 淺談前端建置工具
Vue 淺談前端建置工具Vue 淺談前端建置工具
Vue 淺談前端建置工具andyyou
 
第一次用 Vue.js 就愛上 [改]
第一次用 Vue.js 就愛上 [改]第一次用 Vue.js 就愛上 [改]
第一次用 Vue.js 就愛上 [改]Kuro Hsu
 
Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & VuexBernd Alter
 
Room with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.jsRoom with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.jsZachary Klein
 

Tendances (20)

An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Vue, vue router, vuex
Vue, vue router, vuexVue, vue router, vuex
Vue, vue router, vuex
 
Vue.js Getting Started
Vue.js Getting StartedVue.js Getting Started
Vue.js Getting Started
 
Vue.js
Vue.jsVue.js
Vue.js
 
How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0
 
Vue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue routerVue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue router
 
Vue js 大型專案架構
Vue js 大型專案架構Vue js 大型專案架構
Vue js 大型專案架構
 
Vue.js
Vue.jsVue.js
Vue.js
 
Javascript MVVM with Vue.JS
Javascript MVVM with Vue.JSJavascript MVVM with Vue.JS
Javascript MVVM with Vue.JS
 
Vue js for beginner
Vue js for beginner Vue js for beginner
Vue js for beginner
 
Scalable Front-end Development with Vue.JS
Scalable Front-end Development with Vue.JSScalable Front-end Development with Vue.JS
Scalable Front-end Development with Vue.JS
 
VueJS: The Simple Revolution
VueJS: The Simple RevolutionVueJS: The Simple Revolution
VueJS: The Simple Revolution
 
introduction to Vue.js 3
introduction to Vue.js 3 introduction to Vue.js 3
introduction to Vue.js 3
 
Enjoy the vue.js
Enjoy the vue.jsEnjoy the vue.js
Enjoy the vue.js
 
VueJS Introduction
VueJS IntroductionVueJS Introduction
VueJS Introduction
 
Vue 淺談前端建置工具
Vue 淺談前端建置工具Vue 淺談前端建置工具
Vue 淺談前端建置工具
 
第一次用 Vue.js 就愛上 [改]
第一次用 Vue.js 就愛上 [改]第一次用 Vue.js 就愛上 [改]
第一次用 Vue.js 就愛上 [改]
 
Vue business first
Vue business firstVue business first
Vue business first
 
Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & Vuex
 
Room with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.jsRoom with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.js
 

Similaire à Vue 2.0 + Vuex Router & Vuex at Vue.js

Drupal point of vue
Drupal point of vueDrupal point of vue
Drupal point of vueDavid Ličen
 
Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Lucas Jellema
 
A New Vue for Web Development
A New Vue for Web DevelopmentA New Vue for Web Development
A New Vue for Web DevelopmentChad Campbell
 
MVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming modelMVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming modelAlex Thissen
 
JSS build and deployment
JSS build and deploymentJSS build and deployment
JSS build and deploymentDavid Szöke
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteorSapna Upreti
 
Oracle JavaScript Extension Toolkit Web Components Bring Agility to App Devel...
Oracle JavaScript Extension Toolkit Web Components Bring Agility to App Devel...Oracle JavaScript Extension Toolkit Web Components Bring Agility to App Devel...
Oracle JavaScript Extension Toolkit Web Components Bring Agility to App Devel...Lucas Jellema
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.jsPagepro
 
ReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparisonReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparison500Tech
 
SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4Jon Galloway
 
Vincent biret azure functions and flow (ottawa)
Vincent biret azure functions and flow (ottawa)Vincent biret azure functions and flow (ottawa)
Vincent biret azure functions and flow (ottawa)Vincent Biret
 
Vincent biret azure functions and flow (toronto)
Vincent biret azure functions and flow (toronto)Vincent biret azure functions and flow (toronto)
Vincent biret azure functions and flow (toronto)Vincent Biret
 
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speech
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speechVue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speech
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speechDivante
 
Vue.js - An Introduction
Vue.js - An IntroductionVue.js - An Introduction
Vue.js - An Introductionsaadulde
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]GDSC UofT Mississauga
 
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»DataArt
 

Similaire à Vue 2.0 + Vuex Router & Vuex at Vue.js (20)

Drupal point of vue
Drupal point of vueDrupal point of vue
Drupal point of vue
 
Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...
 
Vue js and Dyploma
Vue js and DyplomaVue js and Dyploma
Vue js and Dyploma
 
A New Vue for Web Development
A New Vue for Web DevelopmentA New Vue for Web Development
A New Vue for Web Development
 
MVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming modelMVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming model
 
JSS build and deployment
JSS build and deploymentJSS build and deployment
JSS build and deployment
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 
Oracle JavaScript Extension Toolkit Web Components Bring Agility to App Devel...
Oracle JavaScript Extension Toolkit Web Components Bring Agility to App Devel...Oracle JavaScript Extension Toolkit Web Components Bring Agility to App Devel...
Oracle JavaScript Extension Toolkit Web Components Bring Agility to App Devel...
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
ReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparisonReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparison
 
SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4
 
Angular js 2.0
Angular js 2.0Angular js 2.0
Angular js 2.0
 
Asp.net,mvc
Asp.net,mvcAsp.net,mvc
Asp.net,mvc
 
Vincent biret azure functions and flow (ottawa)
Vincent biret azure functions and flow (ottawa)Vincent biret azure functions and flow (ottawa)
Vincent biret azure functions and flow (ottawa)
 
Vincent biret azure functions and flow (toronto)
Vincent biret azure functions and flow (toronto)Vincent biret azure functions and flow (toronto)
Vincent biret azure functions and flow (toronto)
 
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speech
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speechVue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speech
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speech
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
Vue.js - An Introduction
Vue.js - An IntroductionVue.js - An Introduction
Vue.js - An Introduction
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
 
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
 

Plus de Takuya Tejima

Nest.js Introduction
Nest.js IntroductionNest.js Introduction
Nest.js IntroductionTakuya Tejima
 
モダンフロントエンド開発者に求められるスキルとは
モダンフロントエンド開発者に求められるスキルとはモダンフロントエンド開発者に求められるスキルとは
モダンフロントエンド開発者に求められるスキルとはTakuya Tejima
 
Next.js Storybook Driven Development
Next.js Storybook Driven DevelopmentNext.js Storybook Driven Development
Next.js Storybook Driven DevelopmentTakuya Tejima
 
グローバルエンジニアキャリア はじめの一歩
グローバルエンジニアキャリア はじめの一歩グローバルエンジニアキャリア はじめの一歩
グローバルエンジニアキャリア はじめの一歩Takuya Tejima
 
GAOGAO発表資料〜エンジニアギルドミートアップ〜
GAOGAO発表資料〜エンジニアギルドミートアップ〜GAOGAO発表資料〜エンジニアギルドミートアップ〜
GAOGAO発表資料〜エンジニアギルドミートアップ〜Takuya Tejima
 
Laravel管理画面ジェネレーター
Laravel管理画面ジェネレーターLaravel管理画面ジェネレーター
Laravel管理画面ジェネレーターTakuya Tejima
 
エンジニア・コミュニティ・ドリブンで会社を成長させていくGAOGAO
エンジニア・コミュニティ・ドリブンで会社を成長させていくGAOGAOエンジニア・コミュニティ・ドリブンで会社を成長させていくGAOGAO
エンジニア・コミュニティ・ドリブンで会社を成長させていくGAOGAOTakuya Tejima
 
「コリビング&コワーキング / スキルアップ / ジョブマッチング / 起業支援」GAOGAO(ガオガオ)エンジニア事務所 18
 「コリビング&コワーキング / スキルアップ / ジョブマッチング / 起業支援」GAOGAO(ガオガオ)エンジニア事務所 18  「コリビング&コワーキング / スキルアップ / ジョブマッチング / 起業支援」GAOGAO(ガオガオ)エンジニア事務所 18
「コリビング&コワーキング / スキルアップ / ジョブマッチング / 起業支援」GAOGAO(ガオガオ)エンジニア事務所 18 Takuya Tejima
 
GAOGAO (ガオガオ) サービス事業概要 2018年8月
GAOGAO (ガオガオ) サービス事業概要 2018年8月GAOGAO (ガオガオ) サービス事業概要 2018年8月
GAOGAO (ガオガオ) サービス事業概要 2018年8月Takuya Tejima
 
GAOGAOゲート2期生サービス概要資料
GAOGAOゲート2期生サービス概要資料GAOGAOゲート2期生サービス概要資料
GAOGAOゲート2期生サービス概要資料Takuya Tejima
 
GAOGAO事業のご紹介
GAOGAO事業のご紹介GAOGAO事業のご紹介
GAOGAO事業のご紹介Takuya Tejima
 
Global Creators Workshop in Asia
Global Creators Workshop in AsiaGlobal Creators Workshop in Asia
Global Creators Workshop in AsiaTakuya Tejima
 
Global Startup Creators vol.5 - Facebook bot development handson
Global Startup Creators vol.5 - Facebook bot development handsonGlobal Startup Creators vol.5 - Facebook bot development handson
Global Startup Creators vol.5 - Facebook bot development handsonTakuya Tejima
 
Parseでちゃんとアプリを作るコツ
Parseでちゃんとアプリを作るコツParseでちゃんとアプリを作るコツ
Parseでちゃんとアプリを作るコツTakuya Tejima
 
React Canvasで作るFlappy Bird
React Canvasで作るFlappy BirdReact Canvasで作るFlappy Bird
React Canvasで作るFlappy BirdTakuya Tejima
 

Plus de Takuya Tejima (16)

Nest.js Introduction
Nest.js IntroductionNest.js Introduction
Nest.js Introduction
 
モダンフロントエンド開発者に求められるスキルとは
モダンフロントエンド開発者に求められるスキルとはモダンフロントエンド開発者に求められるスキルとは
モダンフロントエンド開発者に求められるスキルとは
 
Next.js Storybook Driven Development
Next.js Storybook Driven DevelopmentNext.js Storybook Driven Development
Next.js Storybook Driven Development
 
グローバルエンジニアキャリア はじめの一歩
グローバルエンジニアキャリア はじめの一歩グローバルエンジニアキャリア はじめの一歩
グローバルエンジニアキャリア はじめの一歩
 
GAOGAO発表資料〜エンジニアギルドミートアップ〜
GAOGAO発表資料〜エンジニアギルドミートアップ〜GAOGAO発表資料〜エンジニアギルドミートアップ〜
GAOGAO発表資料〜エンジニアギルドミートアップ〜
 
Laravel管理画面ジェネレーター
Laravel管理画面ジェネレーターLaravel管理画面ジェネレーター
Laravel管理画面ジェネレーター
 
エンジニア・コミュニティ・ドリブンで会社を成長させていくGAOGAO
エンジニア・コミュニティ・ドリブンで会社を成長させていくGAOGAOエンジニア・コミュニティ・ドリブンで会社を成長させていくGAOGAO
エンジニア・コミュニティ・ドリブンで会社を成長させていくGAOGAO
 
「コリビング&コワーキング / スキルアップ / ジョブマッチング / 起業支援」GAOGAO(ガオガオ)エンジニア事務所 18
 「コリビング&コワーキング / スキルアップ / ジョブマッチング / 起業支援」GAOGAO(ガオガオ)エンジニア事務所 18  「コリビング&コワーキング / スキルアップ / ジョブマッチング / 起業支援」GAOGAO(ガオガオ)エンジニア事務所 18
「コリビング&コワーキング / スキルアップ / ジョブマッチング / 起業支援」GAOGAO(ガオガオ)エンジニア事務所 18
 
GAOGAO (ガオガオ) サービス事業概要 2018年8月
GAOGAO (ガオガオ) サービス事業概要 2018年8月GAOGAO (ガオガオ) サービス事業概要 2018年8月
GAOGAO (ガオガオ) サービス事業概要 2018年8月
 
GAOGAOゲート2期生サービス概要資料
GAOGAOゲート2期生サービス概要資料GAOGAOゲート2期生サービス概要資料
GAOGAOゲート2期生サービス概要資料
 
GAOGAO事業のご紹介
GAOGAO事業のご紹介GAOGAO事業のご紹介
GAOGAO事業のご紹介
 
Global Creators Workshop in Asia
Global Creators Workshop in AsiaGlobal Creators Workshop in Asia
Global Creators Workshop in Asia
 
Global Startup Creators vol.5 - Facebook bot development handson
Global Startup Creators vol.5 - Facebook bot development handsonGlobal Startup Creators vol.5 - Facebook bot development handson
Global Startup Creators vol.5 - Facebook bot development handson
 
Parseでちゃんとアプリを作るコツ
Parseでちゃんとアプリを作るコツParseでちゃんとアプリを作るコツ
Parseでちゃんとアプリを作るコツ
 
DevMorning
DevMorningDevMorning
DevMorning
 
React Canvasで作るFlappy Bird
React Canvasで作るFlappy BirdReact Canvasで作るFlappy Bird
React Canvasで作るFlappy Bird
 

Dernier

Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 

Dernier (20)

Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 

Vue 2.0 + Vuex Router & Vuex at Vue.js

  • 1. Vue 2.0 + Vue Router & Vuex Indie Inc. Co-founder & CTO Takuya Tejima
  • 2. Who • Takuya Tejima @tejitak • Co-founder & CTO at Indie Inc. • Server & Web Front-end, iOS Engineer • DevMorning community founder • http://devmorning.connpass.com/ • Vue.js core team member
  • 3. Vue.js MeetUp Tokyo! • 2016/5/31 • Vue.js Tokyo v-meetup="#1" • http://vuejs- meetup.connpass.com/event/31139/ • Evan creator of Vue.js joined via Skype! • He said “Vue.js is for everyone, not for a company”
  • 5. Vue Component Example <template> <div id="app"> <img src="./assets/logo.png"> <h1>{{ msg }}</h1> </div> </template> <script> export default { data () { return { msg: 'Hello Vue 2.0!' } } } </script> <style> body { font-family: Helvetica, sans-serif; } </style> Example of App.vue with webpack https://github.com/vuejs-templates/webpack-simple-2.0
  • 7. Our JavaScript framework is faster than React rendering speed and memory consumption by up to 2-4x in m ww.infoworld.com/article/3063615/javascript/vuejs-lead-our-javascript-framework-is-faster-than-re
  • 8. Vue 2.0 Features • Fast! • Rendering layer is based on Snabbdom (a lightweight virtual-DOM implementation) https://github.com/paldepind/snabbdom • Compiler & Runtime are now separated • Reactive! • No need for shouldComponentUpdate / immutable • Template ? JSX? • You can use both with original template & new render function • Sever Side Rendering! (Streaming SSR) • NativeRendering • Compatibility with v1.0
  • 9. Vue 2.0 API Changes • Lots of APIs are deprecated https://github.com/vuejs/vue/issues/2873 • Filter! (e.g. <span v-text="message | reverse"></span>) • only available in text interpolations {{}} • no build-in filters • vm.$dispatch -> Vuex event bus • vm.$appendTo -> Just use native DOM API • v-for $index & $key -> (value, index) in arr, (value, key) in obj • etc.
  • 12. Popular Frameworks for SPA Implementation • How to implement a SPA (Single-page Application) • Backbone, Ember, Riot, Angular + ui-router, Angular2, React + React-Router (+ Redux), Vue.js + Vue-Router (+ Vuex) • Important things to introduce • Does your app really need to be a SPA? • For example, do you need partial rendering? • Choose framework depending on your app characteristics
  • 13. What’s Vue-Router • Creating a SPA with Vue.js + vue-router is dead simple • Not only client-side routing (hash / history API), but also module based URL mapping • Nested routes and sub components • Async load • etc. • The following hooks are available • data, activate, deactivate, canActivate, canDeactivate, canReuse • NOTE The hooks will be changed to onEnter, onLeave, onChange in Vue-Router v0.8.0 • https://github.com/vuejs/vue-router/issues/321
  • 14. Nested Routes and Sub Components & Hooks Example URL change: /a/b/c -> /a/d/e 2. Validation phase Check if all current components can be activated / deactivated 3. Activation phase Deactivate current components and activate new components with data hook 1. Reusability phase Check reusability
  • 15. Code Example main.vue router.map({ '/about': { component: require('./components/about.vue') }, '/user/:userId': { component: require('./components/user/index.vue'), subRoutes: { 'profile/:something': { component: require('./components/user/profile.vue') } }, '*': { component: require('./components/not-found.vue') }, }) app.vue <template> <div> <p v-show="authenticating" style="color:red">Authenticating...</p> <h1>App Header</h1> <a v-link="{ path: '/about' }">about</a> <a v-link="{ path: '/user/1234/profile/what' }">user</a> <a v-link="{ path: '/mypage' }">mypage</a> <router-view class="view" transition="test" transition-mode="out-in" keep- alive></router-view> </div> </template> components/user/index.vue <template> <div> <h2>User yo</h2> <router-view></router-view> </div> </template> components/user/profile.vue
  • 16. Authentication router.beforeEach((transition) => { if (transition.to.path === '/mypage') { router.app.authenticating = true // check if the user is authenticated api.checkAuth().then(() => { router.app.authenticating = false // authentication success transition.next() }).catch(() => { router.app.authenticating = false // authentication failed transition.abort() }) } else { transition.next() } }) Example auth page implementation with global before hook
  • 17. Is Vue-Router Enough? • If your SPA with Vue-Router has complex component state structures, Vuex could be a solution • Basically, more communications (e.g. dispatch & broadcast) between components leads to unreadable code
  • 18. Vuex
  • 19. Vuex • Official redux inspired flux framework for Vue.js • Vuex is more fit for Vue.js with efficient reactive system such as data reactive rendering & components systems
  • 20. Vuex • Features • Store • basically a container that holds your application reactive states • only way to change a store's state is by explicitly dispatching mutations • Mutation • sync (can not be async) • split into modules with corresponding slice of the state • Action • dispatch mutations • can be async • Advantages • simple unidirectional flow (less side effects) • easy undo/redo - time travel • hot reloading • easy test
  • 21. Vuex Flow Summary with Counter Example
  • 22. Mutation Example • Mutation (a name and a handler) mutates states with synchronous functions • Vuex store's state is made reactive by Vue • When we mutate the state, Vue components observing the state will update automatically import Vuex from 'vuex' const store = new Vuex.Store({ state: { count: 1 }, mutations: { INCREMENT (state) { // mutate state state.count++ } } }) store.dispatch('INCREMENT') • Must be called by dispatch in Action
  • 23. What’s a Getter • A getter provides accessing way to store data from components • Components are not allowed to directly mutate a state • It allows us to reuse computed methods (e.g. totals, averages) through a getter - Getter Example // getters.js export function filteredMessages (state) { return state.messages.filter(message => message.threadID === state.currentThreadID) } - Component <script> export default { vuex: { getters: { filteredMessages } } } </script> <template> <div> <ul> <li v-for="msg in filteredMessages">{{mgs.title}}</li> </ul> </div> </template> NOTE the design may changed at Vuex 2.0 https://github.com/vuejs/vuex/issues/236
  • 24. Vuex Form Handling v-model directly rewrites store data. This is not the Vuex way (throws an error in strict mode) The Vuex way with v-model - Set a getter value to form value - Dispatch action by UI event (e.g. onclick) Template: <input :value="message" @input=“updateMessage”> JS: actions: { updateMessage: ({ dispatch }, e) => { dispatch('UPDATE_MESSAGE', e.target.value) } }
  • 27. Vue-router-sync • Vue Router x Vuex • Inject (sync) router states to Vuex states • Components can access router data (path, params, query) through vuex getter in components router • https://github.com/vuejs/vuex-router-sync
  • 28. SPA with Awesome Vue Family • If your application is not SPA just use Vue.js • If your SPA … • Needs mapping URL for components / partial rendering -> Vue Router • Needs complex component state structure -> Vuex • Needs both above -> Vuex + Vue Router + Vue Router Sync
  • 29. Join Vue.js Community • Vuejs-jp Skack • https://vuejs-jp-slackin.herokuapp.com/ • Translations • Vex docs are working in progress • https://github.com/vuejs/vuex/pull/240