Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Next Vue.js 0.12
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
kazupon
May 27, 2015
4.5k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Next Vue.js 0.12
kazupon
May 27, 2015
More Decks by kazupon
See All by kazupon
プラグインで拡張される Context をtype-safe にする難しさと設計判断
kazupon
2
790
Oxlint JS plugins
kazupon
1
1.3k
gunshi
kazupon
1
230
Nitro v3
kazupon
2
550
わたしのOSS活動
kazupon
3
620
Vapor Revolution
kazupon
3
4.2k
Vue.js最新動向
kazupon
3
1.6k
Vue 3.4
kazupon
13
4.9k
Vue & Vite Rustify
kazupon
4
2.5k
Featured
See All Featured
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
740
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
440
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
KATA
mclloyd
PRO
35
15k
4 Signs Your Business is Dying
shpigford
187
22k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
230
Technical Leadership for Architectural Decision Making
baasie
3
420
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
210
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Transcript
Next Vue.js 0.12 Data Binding JS Night 2015-05-27 @kazupon
ࣗݾհ • @kazupon • ׂɿϦʔυΤϯδχΞ • ࣄɿ։ൃશൠ (ϑϩϯτΤϯυ/όοΫΤϯυ/Πϯϑϥ) •
Vue.jsͱͷؔΘΓɿ Vue.js organizationͷϝϯόͱͯ͠vuejs/vue-validator ͷϝϯςφͯ͠·͢ • ࠷ۙͷJSؔ࿈ͷڵຯɿ FRP | Stream | ServiceWorker | nodejs/NG | electron
͡Ίʹ • ࠓ͓͢Δ༰ɺҎԼͷใͱݱ࣌࠷৽Ͱ͋Δ 0.12βͷಈ࡞֬ೝΛݩʹͨ͠༰Ͱ͢ • Release Tag - https://github.com/yyx990803/vue/releases/tag/0.12.0-beta2 -
https://github.com/yyx990803/vue/releases/tag/0.12.0-beta3 • 0.12 Plan - feedback welcome (vuejs/Discussion) - https://github.com/vuejs/Discussion/issues/158 • ·ͩ։ൃதͳͷͰɺ࠷ऴతʹϦϦʔε͞ΕΔ0.12Ͱɺ ຊൃදͷ༰Λ֬ূͰ͖ΔͷͰ͋Γ·ͤΜ
0.12ͰۄͳϞϊ • ৽ػೳ • async components • element directives •
༷มߋ • partial • filter • v-with directive • paramAttributes option • v-component directive
৽ػೳ
async components
async components • ैདྷͷίϯϙʔωϯτͷ͍ํ Vue.extendͨ͠αϒΫϥε·ͨΦϒδΣΫτΛࢦఆ ͯ͠ಉظతʹొ new Vue({ el: '#app',
data: { a: 1, b: 2 }, components: { child1: Vue.extend({ // case1: Vue.extend template: '<span>child1</span>' }), child2: { // case2: Object template: '<span>child2</span>' } } })
async components • ैདྷͷίϯϙʔωϯτγεςϜʹ͓͚Δ • ΞϓϦ͕ΓΓͯ͠େ͖͘ͳͬͯ͘ΔͱɺΞϓ Ϧॳظϩʔυ͕͘ͳΓ͕ͪ • ίϯϙʔωϯτͷԆϩʔσΟϯάʹΑΔΞϓϦ։ൃ ͔ͳΓΊΜͲ͍͘͞
async components • 0.12Ҏ߱ͰɺίϯϙʔωϯτͷԆϩʔσΟϯάΛ࣮ ͨؔ͠Λࢦఆ͢Δ͜ͱʹΑͬͯɺΛղܾ͢Δ͜ ͱ͕Ͱ͖Δ new Vue({ el: '#app',
components: { child1: function (resolve) { // load component loadComponent(function (component) { resolve(component) // resolve component !! } } } })
async components • ྫ: require.js <!-- HTML --> <div id="app">
<async-child child-msg=“{{message}}"> </async-child> </div> // JS (main) new Vue({ el: '#app', data: { message: 'hello world !!' }, components: { 'async-child': function (resolve) { // with require.js require(['./module1.js'], resolve) } } }) // JS (module1) module.exports = { props: ['child-msg'], template: '<span>{{childMsg}}</span>' } https://jsfiddle.net/kazupon/39mbpaz9/3/
async components • ྫ: webpack (code-splitting) <!-- HTML --> <div
id="app"> <async-child child-msg=“{{message}}"> </async-child> </div> // JS (main) new Vue({ el: '#app', data: { message: 'hello world !!' }, components: { 'async-child': function (resolve) { // with webpack require.ensure(['./module1.js'], function (require) { require(['./module1.js'], resolve) } } } }) // JS (module1) module.exports = { props: ['child-msg'], template: '<span>{{childMsg}}</span>' }
element directives
element directives • ैདྷͷdirective/custom direcitvesɺରͱͳ Δλάʹରͯ͠ଐੑతʹࢦఆ͢Δ͜ͱʹΑͬͯػೳΛ Ճ <!-- vuejs/vue-validatorͷΧελϜσΟϨΫςΟϒͷྫ -->
<form id="blog-form"> <input type="text" v-model="comment" v-validate="minLength: 16, maxLength: 128"> <div> <span v-show="validation.comment.minLength">too long your comment.</span> <span v-show="validation.comment.maxLength">too short your comment.</span> </div> <input type="submit" value="send" v-if="valid"> </form>
element directives • element directivesɺΧελϜλ άશମʹରͯ͠ػೳΛՃͰ͖Δ (AngularͷRestrict Eʹ૬) •
࣮ํ๏custom directivesͱಉ ༷ɺbind/update/unbindΛ࣮ • ԼهΞηοτAPIͰొ - Vue.elementDirective (άϩʔόϧΞηοτ) - elementDirectives (ϓϥΠϕʔτΞηοτ) <!-- HTML --> <div id="app"> <element-directive> <p>{{message}}</p> </element-directive> </div> // JS new Vue({ el: '#app', data: { message: 'hello world !!' }, elementDirectives: { // private 'element-directive': { bind: function () { // ... }, update: function (val, old) { // ... }, unbind: function () { // ... } } } })
element directives • custom directivesͱͷҧ͍ 1. argͱexpressionड͚ೖΕෆՄ https://jsfiddle.net/kazupon/gv9wLL94/10/ <!-- HTML
--> <div id="app"> <div> <input type="radio" name="view1" value="view1" v-model="view"> <input type="radio" name="view2" value="view2" v-model="view"> </div> <p>current view : <view>view1</view></p> <div> # element directive ͷҾͷ༰ <p>name: {{name}}</p> <p>arg: {{arg}}</p> <p>expression: {{expression}}</p> <p>raw: {{raw}}</p> </div> </div> new Vue({ data: { view: ‘view1' }, elementDirectives: { view: { bind: function () { var self = this this.vm.$set('arg', this.arg) // undefined this.vm.$set('expression', this.expression) // “” this.vm.$set('raw', this.raw) // “” this.vm.$set('name', this.name) // view this._watcher = this.vm.$watch('view', function (val, old) { self.update(val, old) }) }, ...
element directives • custom directivesͱͷҧ͍ 2. λʔϛφϧͳσΟϨΫςΟϒͳͷͰɺΧελϜλάʹ͋Δࢠͷλάʹ ରͯ͠ίϯύΠϧॲཧ͕εΩοϓ͞ΕΔ ͭ·Γ
- ΧελϜλάΛDOMΛͬͯࣗ༝ʹૢ࡞͢Δ͜ͱ͕Ͱ͖Δ - VueίϯϙʔωϯτͷΠϯελϯεੜͷΦʔόʔϔου͕ͳ͍ ͳͷͰɺ ύϑΥʔϚϯε͕ٻΊΒΕΔίϯϙʔωϯτΛ࡞Δʹɺίϯϙʔωϯτγ εςϜͷΦϧλφςΟϒͳͷͱͯ͠ར༻Ͱ͖Δ
element directives • element directivesΛͬͨͷ • Vue.js͕ఏڙ͢Δϧʔλ (WIP) vuejs/vue-router https://github.com/vuejs/vue-router
༷มߋ
partial
partial • v-partial directiveͱ{{>partial}}ϒϩοΫͷഇ ࢭ •
͜Εʹ͍ɺpartialΛొ͢ΔΞηοτAPIআ (άϩʔόϧɺϓϥΠϕʔτ྆ํ) <!-- v-partial directive --> <div v-partial="{{partialId}}"></div> <!-- partial block --> <div>{{>my-partial}}</div>
ͳͥഇࢭ͢Δͷ͔ʁ partial
partial • partialจࣈྻϕʔεͷςϯϓϨʔτ͔ΒͷҨ࢈ • ίϯϙʔωϯτϕʔεͳVue.jsͰ͋·Γ༗༻Ͱͳ͍ ͨΊ
filter
filter • ϑΟϧλҾʹจࣈྻΛ͢߹ɺγϯάϧΫΥʔτ (‘’)ඞਢ <!-- 0.11 --> <input v-on="keyup: submitForm
| key enter"> <!-- 0.12 later --> <input v-on="keyup: submitForm | key 'enter'">
filter • $dataΛͬͨಈతͳϑΟϧλҾͷαϙʔτ https://jsfiddle.net/kazupon/q2kykpuz/ <!-- HTML --> <div id="app"> <form>
<input type="text" v-model="first"> <input type="text" v-model="last"> </form> <div> <span>{{first | concat last}}</span> </div> </div> // JS new Vue({ data: { first: '', last: '' }, filters: { concat: function (val, arg) { return val + arg } } }).$mount('#app')
v-with directive
v-with directive • v-with directiveഇࢭ <!-- HTML --> <div id="app">
<p v-component="user-profile" v-with="user"></p> </div>iv> // JS Vue.component('user-profile', { template: '{{name}}<br>{{email}}' }) var parent = new Vue({ el: '#app', data: { user: { name: 'Foo Bar', email: '
[email protected]
' } }
ͳͥഇࢭ͢Δͷ͔ʁ v-with directive
v-with directive • ςϯϓϨʔτͷ{{#with}}ϒϩοΫͰσʔλΛड͚͢ ํ๏ΛσΟϨΫςΟϒԽͨ͠ෛͷҨ࢈ͳͷͰআ͍ͨ͠ <!-- Handlesbars --> <div id=“app">
{{#with user}} <p> {{{name}}}<br>{{{email}}} </p> {{/with}} </div>>
v-with directive • 0.11ͰσʔλΛɺࢠʹରͯ͠໌ࣔతʹड͚͢ํ๏͕ 2͔ͭ͋ͬͯΓʹ͍͘ # paramAttributes option ʹΑΔํ๏ <!--
HTML --> <div id="app"> <input v-model="parentMsg"> <child-component child-msg="parentMsg"></child-component> </div> // JS new Vue({ el: '#app', data: { parentMsg: 'parent message' }, components: { 'child-component': { paramAttributes: ['child-msg'], template: '<span>{{childMsg}}</span>' } } })
v-with directive • 0.12Ҏ߱Ͱࢠͷσʔλͷड͚͠ɺࢠͷprops optionܦ༝Ͱ౷Ұ͢Δ <!-- HTML --> <div id="app">
<input type="text" v-model="parentMsg"> <child child-msg="{{parentMsg}}"></child> </div> // JS new Vue({ el: '#app', data: { parentMsg: 'hello world !!' }, components: { child: { props: ['child-msg'], template: '<span>{{childMsg}}</span>' } } }) https://jsfiddle.net/kazupon/7ph214eg/4/
v-with directive • ࢠͷ$dataΛյͯ͠͠·͏ ex1: $dataʹҙਤ͠ͳ͍ϓϩύςΟΛੜͯ͠͠·͏ <!-- HTML --> <div
id="app1"> <p># v-withͳ͠</p> <div v-component="child"></div> </div> <div id="app2"> <p># v-withͰͷnumberΛࢠͷcountͱͯ͠ࢦఆ </p> <div v-component="child" v-with="count: number"></div> </div> // JS var child = { template: '<span>{{$data|json}}</span>', data: function () { return { msg: 'hello' } } } var app1 = new Vue({ components: { child: child } }).$mount('#app1') var app2 = new Vue({ data: { number: 3 }, components: { child: child } }).$mount('#app2') http://jsfiddle.net/kazupon/pqw77weq/3/
v-with directive • ࢠͷ$dataΛյͯ͠͠·͏ ex2: $dataͷॳظΛม͑ͯ͠·͏ <!-- HTML --> <div
id="app1"> <p># v-withͳ͠</p> <div v-component="child"></div> </div> <div id="app2"> <p># v-withͰσʔλΛॻ͖͑ͯ͠·͏</p> <div v-component="child" v-with="msg: say"></div> </div> // JS var child = { template: '<span>{{$data|json}}</span>', data: function () { return { msg: 'hello' } } } var app1 = new Vue({ components: { child: child } }).$mount('#app1') var app2 = new Vue({ data: { say: 'world' }, components: { child: child } }).$mount('#app2') http://jsfiddle.net/kazupon/tceb6wLt/2/
paramsAttribute option
paramsAttbites option • Φϓγϣϯ໊propsʹ มߋ • {{*prop}}ͰҰํ (one-way)ͳόΠϯ σΟϯάͱͯ͠໌ࣔతʹ ࢦఆ͕Ͱ͖Δ
https:// jsfiddle.net/ kazupon/cecypzan/3/ <!-- HTML --> <div id="app"> <div> <span>:</span> <input type="text" v-model="parentMsg"> </div> <div> <child child-msg="{{*parentMsg}}"></child> </div> </div> // JS new Vue({ el: '#app', data: { parentMsg: 'hello world !!' }, components: { child: { props: ['child-msg'], template: '<span>ࢠ:{{childMsg}}</span> <br><input type="text" v-model="childMsg">' } } })
paramsAttbites option • ෳͷmustacheΛɺprops optionͰఆٛͨ͠ϓϩύ ςΟʹࢦఆ͕Ͱ͖Δ <!-- HTML --> <div
id="app"> <child child-msg="{{a}} {{b}}"></child> </div> // JS new Vue({ el: '#app', data: { a: 1, b: 2 }, components: { child: { props: ['child-msg'], template: '<span>{{childMsg}}</span>' } } }) https://jsfiddle.net/24ch88n2/2/
paramsAttbites option • ϑΟϧλؚΊΔ͜ͱ͕Ͱ͖Δ <!-- HTML --> <div id="app"> <child
child-msg="{{msg | uppercase}}"></child> </div> // JS new Vue({ el: '#app', data: { msg: 'hello' }, components: { child: { props: ['child-msg'], template: '<span>{{childMsg}}</span>' } } }) https://jsfiddle.net/kazupon/ondpvuk8/1/
paramsAttbites option • expressionsΛؚΊΔ͜ͱͰ͖Δ https://jsfiddle.net/kazupon/pnszx8rc/1/ <!-- HTML --> <div id="app">
<child child-msg="{{a}} + {{b}} = {{a + b}}"></child> </div> // JS new Vue({ el: '#app', data: { a: 1, b: 2 }, components: { child: { props: ['child-msg'], template: '<span>{{childMsg}}</span>' } } })
paramsAttbites option • ͷϓϩύςΟ͕ઃఆՄೳͰͳ͍ͱ͖ɺϓϩύςΟ ࣗಈతʹҰํͳόΠϯσΟϯάʹͳΔ <!-- HTML --> <div id="app">
<child child-msg="{{a + b}}"></child> </div> // JS new Vue({ el: '#app', data: { a: 1, b: 2 }, components: { child: { props: ['child-msg'], template: '<span>{{childMsg}}</span>' } } })
v-component directive
v-component directive • v-component directiveഇࢭ • ࠓޙΧελϜλάͰί ϯϙʔωϯτΛར༻͢Δ (ϋΠϑϯ”-“ඞਢͰ ͳ͘ͳͬͨ)
<!-- HTML --> <div id="app"> <input type="text" v-model="message"> <view text="{{message}}"></view> </div> // JS new Vue({ el: '#app', data: { message: 'hello world !!' }, components: { view: { props: ['text'], template: '<span>{{text}}</span>' } } }) https://jsfiddle.net/kazupon/Lkqdd1y0/
v-component directive • ಈతͳίϯϙʔωϯτ<component is=“{{view}}”> <!-- HTML --> <div id="app">
<component is="{{view}}"></component> <input type="radio" name="view1" value="view1" v-model="view"> <input type="radio" name="view2" value="view2" v-model="view"> </div> // JS new Vue({ el: '#app', data: { view: ‘view1' }, components: { view1: { template: '<span>view1</span>' }, view2: { template: '<span>view2</span>' } } }) https://jsfiddle.net/kazupon/oev3bahL/2/
ͦͷଞ
ͦͷଞ • Vue.jsެࣜϓϥάΠϯͷαϙʔτ͕૿͑ͨ • vuejs/vue-router (WIP) https://github.com/vuejs/vue-router • vuejs/vue-resource https://github.com/vuejs/vue-resource
·ͱΊ
·ͱΊ • 0.12Ͱ͍͔ͭ͘ͷ৽ػೳͱ༷มߋ͕͋Δ • ৽ػೳͱ༷มߋʹΑΓɺVue.jsΛͬͨ։ൃ͕͠қ ͘ͳͬͨΓɺύϑΥʔϚϯεվળՄೳ • ༷มߋʹ͓͍ͯɺAPIͷI/FͷBreakతͳมߋ͕͋ ΔͷͰɺچόʔδϣϯ͔ΒόʔδϣϯΞοϓ͢Δࡍɺ ରԠ͕ඞཁ
͓·͚
None
Roetem • Vue.js+RethinkDBʹΑΔMeteorϥΠΫͳ࣮ݧతͳ ϓϩδΣΫτ https://github.com/yyx990803/roetem • কདྷɺVue.jsͷΑ͏ʹɺطଘͷͷʹΈࠐΊΔΑ͏ͳ γϯϓϧͳϥΠϒϥϦΛ࡞Δ͔͠Εͳ͍ (Evanࢯίϝϯτ) https://github.com/yyx990803/roetem/issues/1
ެࣜαΠτͷ༁ • ༗ࢤͰެࣜαΠτ vue.orgͷຊޠ༁Λ ͍ͬͯ·͢ https://github.com/ vuejs-jp/vuejs.org • དྷ݄6݄͋ͨΓαΠτެ ։༧ఆ
vuejs-jpຊϢʔβʔάϧʔϓൃ • ༁ϓϩδΣΫτͷ༗ࢤͰຊϢʔβʔάϧʔϓΛཱͪ ্͛·ͨ͠ https://github.com/vuejs-jp • ࠓޙͷ׆ಈ༧ఆ • ެࣜαΠτ༁ •
ษڧձ • ϒϩάʹΑΔใڞ༗
͝੩ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ