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
Function API You will use in future
Search
jiko21
July 24, 2019
Programming
1.7k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Function API You will use in future
V-kansai#8の登壇資料です。
jiko21
July 24, 2019
More Decks by jiko21
See All by jiko21
型情報を手繰り寄せる技術~TypeScript Compiler APIによる型解析実践~
jiko21
0
1.2k
Creating a Next.js-style Framework with Bun and Hono
jiko21
0
180
Array Grouping will soon be arriving at TypeScript
jiko21
0
170
Copying Array Methods arrived at TypeScript
jiko21
1
900
SSRで動的に OGP画像を生成したい! 〜Cloudflare Workersから@vercel/og移行編〜
jiko21
0
170
node:test will replace Jest?
jiko21
0
120
どこでも動かすために… TypeScriptでライブラリ開発の すゝめ
jiko21
2
450
NestJS a progressive web framework
jiko21
3
2.3k
レガシーなフロントエンドをリプレイスする
jiko21
5
1.6k
Other Decks in Programming
See All in Programming
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.5k
JavaDoc 再入門
nagise
1
410
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
7.8k
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.5k
Strategic Design in the Frontend: Moduliths & Micro Frontends @DDDEurope
manfredsteyer
PRO
0
130
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
140
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
800
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
200
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
610
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
300
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
180
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.4k
Featured
See All Featured
AI: The stuff that nobody shows you
jnunemaker
PRO
8
730
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
260
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
850
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
420
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
310
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
220
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Thoughts on Productivity
jonyablonski
76
5.2k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Transcript
Function API You will use in future v-kansai Vue.js/Nuxt.js meetup
#8 @Daikids2
খౡ େج / Daiki Kojima @Daikids2 @daikikojima ژେֶେֶӃใֶݚڀՊM2 Server/Front, Mobile(iOS/Android)…
Vue fes JPࢀՃ͠·͢!! ࠷ۙFlutterָ͕͍͠…
Posted on … IUUQTTQFBLFSEFDLDPNEBJLJETGVODUJPOBQJZPVXJMMVTFJOGVUVSF
Today’s Topic • Vue 3? • Function API
Vue 3?
Vue 3͕ࠓதʹͰΔͬΆ͍ https://vuefes.jp/2019/
None
RFCʹ͓͚Δݱঢ় ௨ͬͨͷ ৹ٞத ٫Լ (MPCBM"1* 5SFFTIBLJOH 'VODUJPO"1* 7NPEFM"1* $IBOHF
$VTUPN%JSFDUJWF "1*$IBOHF FUDʜ $MBTT4UZMFBQJ ※ࣈഁյతมߋ
ͪͳΈʹ…
Global API TreeShaking • Vue.<͍͍ͨmodule>͡Όͳͯ͘ɺ named exportΛͬͯapiΛར༻͢Δ͜ͱʹ… • Named exportͳͷͰ
Webpackʹ͓͍ͯෆཁͳίʔυ(σουίʔυ) ͷBundleԽΛ͛Δ!!
What’s Function API?
Function API? • Vue 3ʹͯొ(༧ఆ)ͷAPI • ࠓͪΐ͏ͲRFCͰٞத • ͜ΕࣗମVue 2Ͱ
(ϞδϡʔϧͷಋೖͰ) ར༻Մೳ • ࠓ·Ͱͱॻ͖ํ͕ҧ͏? →ݟ͍͖ͯ·͠ΐ͏!!
• Πϯετʔϧͪ͜Β • main.jsʹͯ ͜ͷΑ͏ʹ install ಋೖ $ npm install
vue-function-api --save import Vue from "vue"; import App from "./App.vue"; import store from "./store"; import "./registerServiceWorker"; import { plugin } from 'vue-function-api' Vue.use(plugin)
؆୯ͳαϯϓϧ
ެࣜͷαϯϓϧΛݟͯΈΔ <template> <div class="count"> <span>count is {{ count }}</span> <span>plusOne
is {{ plusOne }}</span> <button @click="increment">count++</button> </div> </template> IUUQTHJUIVCDPNWVFKTWVFGVODUJPOBQJ
ެࣜͷαϯϓϧΛݟͯΈΔ <script> import { value, computed, watch, onMounted } from
'vue-function-api'; export default { setup() { // State const count = value(0); // computed state const plusOne = computed(() => count.value + 1); // Method const increment = () => { count.value++; }; // watch watch( () => count.value * 2, val => { console.log(`cont * 2 is ${val}`); }, ); onMounted(() => { console.log("mounted"); }); return { count, plusOne, increment }; }, }; </script>
جຊ • ObjectΛ࡞Δ • Objectʹؔsetup()Λఆٛͯ͠ɺ ͦͷதʹॲཧΛॻ͍͍ͯ͘ export default { setup()
{ return {}; }, };
Dataͷ࡞ • valueΛ͏! • Ҿ͕ॳظʹͳͬͯ͘ΕΔΑ!! // State const count =
value(0);
DataͷΞΫηε • ม໊.valueͰdataͷʹΞΫηεͰ͖Δ!! count.value++;
Computed state • ࠓ·Ͱcomputedʹॻ͍͍ͯͨͷɺ computedؔΛ༻͍Δ… const plusOne = computed(() =>
count.value + 1);
Method • ΞϩʔؔΛͬͯఆٛ͢Δ͚ͩ!! // Method const increment = () =>
{ count.value++; };
Watch • ࠓ·ͰͷWatchͱগ͠ॻ͖ํ͕มΘͬͯΔ… // watch watch( // getter () =>
count.value * 2, // callback val => { console.log(`cont * 2 is ${val}`); }, ); ࢹ͢ΔΛؔͰฦ͢ ͕มߋ͞ΕͨΒݺͼग़͢
ྫ͑… • ͜ͷΑ͏ͳ߹callback͕ݺΕͳ͍ // watch watch( // getter () =>
count.value * 0, // callback val => { console.log(`cont * 2 is ${val}`); }, ); ৗʹ HFUUFSͷ͕มΘΒݺͼग़͞Εͳ͍
ϥΠϑαΠΫϧؔ • vue-function-apiʹઐ༻ͷ͕ؔ༻ҙ͞Ε͍ͯ·͢… • onXXXXͱ͔ • ҾʹؔΛೖΕͯΕOK onMounted(() => {
console.log("mounted"); });
࠷ޙʹ • statemethodͳͲɺએݴͨ͠ͷΛreturnͰฦ͢ return { count, plusOne, increment };
None
Propsͱ͔Ͳͳ͍͢Δͷ?
࣮… • setupʹҾͱͯ͠propsΛه͢ΕOK • https://github.com/daikikojima/vue-function-api- memo ʹͯpropsΛͬͨ ϝϞΞϓϦΛஔ͍ͯ·͢ɻ export default
{ props: ['addTodo'], setup(props) { const text = value(''); const onAddClick = () => { if (text.value !== '') { props.addTodo(text.value); text.value = ''; } };
৮ͬͯΈͯͷॴײ • ReactͬΆ͍… • ࣮ࡍʹRFCͰʹͳͬͨΓԌ্?ͯͨ͠ • TSͱ૬ੑ͕ྑͦ͞͏…
࠷ޙʹ • ͜͜ͰҰ෦͔͠հ͓ͯ͠Γ·ͤΜɻ ΑΓৄ͍͠ใ https://github.com/vuejs/vue-function-api ʹࡌͬͯ·͢ɻ
Reference? • Vue-function-api https://github.com/vuejs/vue-function-api • Vue rfc (function apiͷproposal) https://github.com/vuejs/rfcs/pull/42
• αϯϓϧͷίʔυ https://github.com/daikikojima/vue-function-api-memo