Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Next Vue.js 0.12
Search
kazupon
May 27, 2015
4.6k
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
2.6k
Oxlint JS plugins
kazupon
1
1.4k
gunshi
kazupon
1
270
Nitro v3
kazupon
2
610
わたしのOSS活動
kazupon
3
660
Vapor Revolution
kazupon
3
4.4k
Vue.js最新動向
kazupon
3
1.7k
Vue 3.4
kazupon
13
4.9k
Vue & Vite Rustify
kazupon
4
2.5k
Featured
See All Featured
Git: the NoSQL Database
bkeepers
PRO
433
67k
Code Reviewing Like a Champion
maltzj
529
40k
Automating Front-end Workflow
addyosmani
1369
210k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
450
New Earth Scene 8
popppiees
4
2.7k
Claude Code のすすめ
schroneko
67
230k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
550
Between Models and Reality
mayunak
4
500
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
Google's AI Overviews - The New Search
badams
0
1.6k
Unsuck your backbone
ammeep
672
58k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
630
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 • ࠓޙͷ׆ಈ༧ఆ • ެࣜαΠτ༁ •
ษڧձ • ϒϩάʹΑΔใڞ༗
͝੩ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ