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
Nuxt.jsのComponent分割単位と,SSRをする上で気をつけること
Search
omiend
January 26, 2019
Programming
820
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Nuxt.jsのComponent分割単位と,SSRをする上で気をつけること
omiend
January 26, 2019
More Decks by omiend
See All by omiend
スクラッチ組織活用術 Salesforce Developers Meetup #24
omiend
0
1.4k
Nuxt.js_Vue.js_のVuexの動かしかたをまとめてみたよ.pdf
omiend
0
120
20181208_好きだけじゃツライScala.js_共有版_.pdf
omiend
0
130
20181110 Scala関西Summit 懇親会LT「Scalaのかわいいところ」
omiend
0
600
Other Decks in Programming
See All in Programming
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
370
setup-vp GitLab対応の裏側
naokihaba
0
150
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
20
21k
プロダクトコードからライブラリの境界を見つける
elmetal
PRO
0
110
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
190
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
230
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
350
カツオ、ご期待ください
suneo3476
0
150
Java 27新機能 / Java 27 new features
kishida
2
200
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
160
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
Security issues being discussed on Web Platforms
petamoriken
0
1.4k
Featured
See All Featured
The Cult of Friendly URLs
andyhume
79
7k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
390
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
210
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
WCS-LA-2024
lcolladotor
0
850
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
590
Believing is Seeing
oripsolob
1
240
How STYLIGHT went responsive
nonsquared
100
6.3k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
260
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
350
Transcript
Nuxt.jsのComponentについて @omiend Store
自己紹介 @omiend 恵比寿で働くプログラマー歴13年目のおじさん 一応フロントエンドからバックエンドまで一通り出来ると思い込んでいるダメェンジニア 時々パン売ってます。(次回予定3月横浜赤レンガ/4月新宿たかしまや) PeopleSoft,Java,Shell,MySQL,SQL,Salesforce(Force.com/ApexCode/VisualCode),GAE(Slim3),ABAP Scala(ScalaMatsuri Staff),Ruby on Rails,Docker,Angular(1.4…),React/Redux,Riot.js,Vue.js,Nuxt.js
Musics,Movies,Joging,Walking,Drink Driven Development
話すこと - Nuxt.js のComponent分割単位 - Nuxt.js SSRする時に気をつけること @omiend 今日も一日
@omiend Nuxt.jsのComponent分割単位
@omiend Nuxt.js は Vue アプリケーションを作成するフレームワークです。 ユニバーサルアプリケーション、静的に生成されるアプリケーショ ン、シングルページアプリケーションの中から作成するアプリケー ションを選ぶことができます。 はじめに -
Nuxt.js https://ja.nuxtjs.org/guide/ Nuxt.jsとは
Nuxtは - Layouts - Pages - Components という単位でページを構成する。 @omiend Nuxt.jsのページ定義
layouts/default.vue pages/index.vue components/TheFooter.vue components/TheHeader.vue components/SomeSection.vue components/ UserCard.vue components/ TheSideNavi.vue components/ UserCard.vue
@omiend 右ののようなページを作成する場合、下記のようなディレクトリ構 造となる。 . ├── components │ ├── TheSideNavi.vue │
├── TheFooter.vue │ ├── TheHeader.vue │ ├── SomeSection.vue │ └── UserCard.vue ├── layouts │ └── default.vue └── pages └── index.vue Nuxt.jsのページ定義 layouts/default.vue pages/index.vue components/TheFooter.vue components/TheHeader.vue components/SomeSection.vue components/ UserCard.vue components/ TheSideNavi.vue components/ UserCard.vue
Layoutsは全ページ共通のレイアウトを定 義するソースファイル。 Nuxtがデフォルトで用意するdefault.vue とは別のソースファイルを定義し、ページご とに適用を分けることもできる。 @omiend Layouts layouts/default.vue pages/index.vue components/TheFooter.vue
components/TheHeader.vue components/SomeSection.vue components/ UserCard.vue components/ TheSideNavi.vue components/ UserCard.vue
Pagesは各ページ(トップページやアバウト ページなど)を定義するソースファイル。 定義したディレクトリによりNuxtがRouting を自動生成してくれる。 @omiend Pages layouts/default.vue pages/index.vue components/TheFooter.vue components/TheHeader.vue
components/SomeSection.vue components/ UserCard.vue components/ TheSideNavi.vue components/ UserCard.vue
Componentsでは、再利用性の高い部品を 定義する。 例では、HeaderやFooter、または GlobalNaviなどを定義してLayoutで importしたり、ユーザ1人1人の情報を表 示するカードを定義している。 @omiend Components layouts/default.vue pages/index.vue
components/TheFooter.vue components/TheHeader.vue components/SomeSection.vue components/ UserCard.vue components/ TheSideNavi.vue components/ UserCard.vue
このComponentsはHTMLの要素としてど の単位にも分割・定義をすることができる。 しかし、設計・再現無く分割・定義しまくると カオス化することが想定される。 では、Componentsはどの粒度で分割して 定義するのが良いか? @omiend Componentsの分割単位 layouts/default.vue pages/index.vue
components/TheFooter.vue components/TheHeader.vue components/SomeSection.vue components/ UserCard.vue components/ TheSideNavi.vue components/ UserCard.vue
ざっくりまとめると、弊社では - (HTML5の)Sectionタグ - 部品(Cardなど) の粒度で分割・定義することとした。 Blogに書きました: #Nuxt.jsのComponentをどの単位で分けるか悩んだ話 https://omiend.hatenablog.jp/entry/2018/12/27/203359 @omiend
layouts/default.vue pages/index.vue components/TheFooter.vue components/TheHeader.vue components/SomeSection.vue components/ UserCard.vue components/ TheSideNavi.vue components/ UserCard.vue Componentsの分割単位
@omiend その上で、書きのディレクトリ構造を少し変更して・・・ . ├── components │ ├── TheSideNavi.vue │ ├──
TheFooter.vue │ ├── TheHeader.vue │ ├── SomeSection.vue │ └── UserCard.vue ├── layouts │ └── default.vue └── pages └── index.vue Componentsの分割単位 layouts/default.vue pages/index.vue components/TheFooter.vue components/TheHeader.vue components/SomeSection.vue components/ UserCard.vue components/ TheSideNavi.vue components/ UserCard.vue
このような感じにしました。 . ├── components │ ├── parts │ │ └──
UserCard.vue │ └── sections │ ├── TheSideNavi.vue │ ├── TheFooter.vue │ └── TheHeader.vue ├── layouts │ └── default.vue └── pages └── index.vue @omiend Componentsの分割単位 layouts/default.vue pages/index.vue components/TheFooter.vue components/sections/TheHeader.vue components/sections/ SomeSection.vue components/ parts/ Card.vue components/ sections/ TheSideNavi.vue components/ parts/ Card.vue
異論は認める。 @omiend Componentsの分割単位 layouts/default.vue pages/index.vue components/TheFooter.vue components/sections/TheHeader.vue components/sections/ SomeSection.vue components/
parts/ Card.vue components/ sections/ TheSideNavi.vue components/ parts/ Card.vue
※SSR = Server Side Rendering SPAだと当該ページにアクセスしてから DOM(仮想DOM)を構築してページを構成するので、クローラーが巡回してきた時は「なにも無いページ」と解釈されてしまう。 そこでSSRにて対応する。 ※SPA =
Single Page Application @omiend Nuxt.jsにおけるSSRのしかた
@omiend 日記はここで終わっている・・・ Nuxt.jsにおけるSSRのしかた
TL;DR - Componentsで利用するデータや機能は、 Components内部で完結させたい - Nuxt.jsでSSRをするときは、asyncData()とfetch()を利用する - ComponentsからはasyncData()を利用することが出来ない( Nuxt.jsの仕様) -
asyncData()はPagesで利用する必要があり、 Componentsにデータを渡す場合は Propsを利用する - Propsは利用したくない - Vuexを利用すれば良い - asyncData()からはVuexのStoreにアクセスできない - fetch()であれば、Storeにアクセスできる まとめ - SSRをしたい - Componentsにデータを渡すか? - Yes - Pagesにfetch()を定義し、Storeにデータを格納 - ComponentsからはStoreのデータを参照する - No - PagesにasyncData()を定義し、Pagesのdata要素とマージさせる @omiend Nuxt.jsにおけるSSRのしかた
ソース https://github.com/omiend/omiend-my-api アプリ(firebase) https://omiend-my-api.firebaseapp.com/ssr @omiend Nuxt.jsにおけるSSRのしかた
@omiend ご清聴 ありがとうございました Store