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
Nuxt Composition API 使ってみた
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
y-tsuzaki
September 17, 2021
Programming
280
0
Share
Nuxt Composition API 使ってみた
y-tsuzaki
September 17, 2021
More Decks by y-tsuzaki
See All by y-tsuzaki
PHPカンファレンス福岡2024 【超特急】SQLアンチパターン総おさらいLT
ytsuzaki
1
1.6k
PHPカンファレンス北海道2024 リーダブルSQL
ytsuzaki
5
830
ある日PHPerがベンチャー企業のデータ基盤を作ることになったら
ytsuzaki
1
450
【PhpStorm】モブプログラミングの実践と学び【結局はバランス?】
ytsuzaki
0
530
PHPerKaigi 2022 【Laravel】 サクッとN + 1問題を見つけて倒しチャオ!
ytsuzaki
1
3.3k
【超特急】「SQLアンチパターン」 総おさらいLT 【4分で25個】
ytsuzaki
2
910
Nuxt.js x Composition API x TypeScript
ytsuzaki
0
810
PHPerKaigi 2021 LT PHPで簡単コード生成! 同じようなコードをたくさん書くなら コード生成しチャイナ!
ytsuzaki
0
160
アクセス制御ライブラリ Casbinを使ってみた
ytsuzaki
2
1.7k
Other Decks in Programming
See All in Programming
Building on Bluesky's AT Protocol with Ruby
mackuba
0
110
10 Tips of AWS ~Gen AI on AWS~
licux
5
540
Cache-moi si tu peux : patterns et pièges du cache en production - Devoxx France 2026 - Conférence
slecache
0
340
Back to the roots of date
jinroq
0
740
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
190
Making the RBS Parser Faster
soutaro
0
670
ローカルLLMでどこまでコードが書けるか / How much code can be written on a local LLM
kishida
2
320
「OSSがあるなら自作するな」は AI時代も正しいか ── Build vs Adopt の新しい判断基準
kumorn5s
7
2.2k
(Re)make Regexp in Ruby: Democratizing internals for the JIT
makenowjust
3
1k
Claude CodeでETLジョブ実行テストを自動化してみた
yoshikikasama
0
1.2k
AI時代のエンジニアリングの原則 / Engineering Principles in the AI Era
haru860
0
1.1k
AgentCore Optimizationを始めよう!
licux
3
210
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
350
Reality Check: Gamification 10 Years Later
codingconduct
0
2.1k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
820
Un-Boring Meetings
codingconduct
0
280
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.1k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
540
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.5k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
350
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
Raft: Consensus for Rubyists
vanstee
141
7.4k
Transcript
Nuxt Composition API 使ってみた 2021年9月17日 v-okinawa 株式会社 M&Aクラウド 津崎 善昭
自己紹介 津崎 善昭(つざき よしあき) Twitter: @820zacky 趣味:たまにキャンプ、たまに筋トレ(サボり中) 得意: 資格勉強 セキュリティスペシャリスト,ネットワークスペシャリスト,データベーススペシャリスト
SIer -> Web制作会社 -> Webベンチャー フロントエンド入門中
None
None
None
※ 北海道出身だけどいじめないでください
None
Composition API とは? Vue.jsのコンポーネントをいい感じに書く手法 2020年9月にリリースされたVue 3にて導入された 標準の書き方はOptions APIという コンポーネントからロジックを分離し、再利用可能にする 大規模・複雑なコンポーネントを作る時に便利
Nuxt.jsでComposition APIを使う2つのやり方 @vue/composition-api と @nuxtjs/comopsition-api
ふたつのやり方と言ったな? あれは嘘だ -> Nuxt3が10/12にリリースになりました https://nuxtjs.org/ja/v3/ もうどちらもいらない!
None
None
最初から入ってる
@vue/composition-api 従来のやり方 Vueの純正composition-api M&Aクラウドが使っているのはこれ SSRとCSRで値をハイドレーションできない問題があり困った (https://speakerdeck.com/kubotak/nuxt-dot-jsdecompositionapiwoshi-u? slide=16) 弊社ではVuexストアを使って値を共有している
@nuxtjs/comopsition-api = Nuxt Composition API 新しいやり方 nuxt-communityが提供している Nuxt 3 のための実験的なもの
Nuxt 3 ではメソッド名がかわるかもしれない Nuxt固有の機能を使える 弊社もこちらへの意向を検討中
Nuxt Composition API @vue/composition-apiの機能に加えてNuxt固有の機能を提供している useMeta : Metaタグの情報にアクセスするメソッド useAsync : NuxtのAsyncDataフックを使うメソッド
useFetch : NuxtのFetchフックを使うメソッド など reqRef, reqSsrRef, ssrRefなど新しい概念も登場している (まだよくわかってないがSSRとCSRで値を共有する方法っぽい)
なぜComposition APIなのか
処理をまとめられる
(無理矢理拡大した図) data()内にいろんな関心事の変数が定義されている
関心事ごとに変数を用意できる
ロジックを抽出して再利用 ref, reactiveなどのリアクティブな値を作成するメソッドや、onMountedなどのコ ールバック登録するメソッドなど、細かく機能が分割されているため、共通化した いロジックや肥大化したロジックを別ファイルに移することができる。 Options APIではMixinというTrait的なやり方でしか分離できず、再利用性が悪かっ た
Nuxt Composition APIの開発環境を作る
Nuxtインストール yarn create nuxt-app sample-app 言語はTypeScriptを選択する Composition APIを導入する yarn add
@nuxtjs/composition-api 今回は新しいやりかたである@nuxtjs/composition-apiを試してみる
nuxt.config.jsを編集する { buildModules: [ '@nuxt/typescript-build', + '@nuxtjs/composition-api/module' ] }
サーバーを起動する yarn dev localhost:3000でサイトが起動する
サンプルコード https://qiita.com/zackey2/items/8a2675c14d73e91267fe
まとめ Nuxt3 10/12リリース予定 Nuxt3 では最初から Composition APIが使えます!