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
コンポーネント間のデータやりとりを色々試してみた.pdf
Search
hatsune
July 01, 2020
Programming
530
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
コンポーネント間のデータやりとりを色々試してみた.pdf
hatsune
July 01, 2020
More Decks by hatsune
See All by hatsune
フロントエンド_最強ディレクトリ構成
kitsuneeee
1
5.3k
Vue_CLIプロジェクトにViteを導入検討してみた
kitsuneeee
1
8.2k
Vue.js + TypeScriptによる 新規サービス開発の振り返り/frontend-looking-back
kitsuneeee
4
2.2k
Other Decks in Programming
See All in Programming
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
450
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
300
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1k
Heart of Swift Concurrency
koher
0
920
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
4
710
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
240
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
5
3.5k
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
120
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
500
AI × TiDD / 2026.09.05 Redmine 大阪
tokudiro
1
180
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
2.3k
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
300
Featured
See All Featured
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
890
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
600
The agentic SEO stack - context over prompts
schlessera
0
940
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
530
The World Runs on Bad Software
bkeepers
PRO
72
12k
Google's AI Overviews - The New Search
badams
0
1.6k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
530
Designing for Performance
lara
611
70k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
57k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
Writing Fast Ruby
sferik
630
63k
Transcript
コンポーネント間のやりとり いろいろ試してみた 株式会社ラクス UI開発課 北嶋 初音
index • 自己紹介 • Vue.jsのコンポーネント間のやりとり(demo) ◦ props ◦ emit ◦
getter, setter ◦ v-model ◦ 配列・オブジェクトの変更 ◦ refs • まとめ
自己紹介:北嶋 初音 • Web業界5年目 • 前職ではバックエンドも触ってた • 今年1月にラクスに入ってからフロントエンド専任 • 新規サービスの開発に参画中
+
Props:親→子へのデータ受け渡し // script部分 public message = "メッセージ"; // template部分 <child
:message="message" message2="message" /> // script部分 @Prop() message!: string; @Prop() message2!: string; Parent.vue Child.vue message = “メッセージ” message2 = “message” ・変数展開したい場合はコロン付き ・リテラルの場合はコロンなし
Props:親→子へのデータ受け渡し // script部分 public message = "メッセージ"; // template部分 <child
:message="message" /> // script部分 @Prop(Number) message!: number; @Prop({default: 'default'}) message2!: string; Parent.vue Child.vue ・型指定も可能 (コンソールエラーを出してくれる) ・デフォルト値が指定可能 message2 = 'default'
Props:親→子へのデータ受け渡し // script部分 public message = "メッセージ"; // template部分 <child
:message="message" message2="message" /> // script部分 @Prop() message!: string; @Prop() message2!: string; public changeMessage() { this.message = "書き換え"; } Parent.vue Child.vue ・子での直接書き換えはNG ・親側で書き換える
emit:親←子 のデータ受け渡し // script部分 public message = "メッセージ"; public changeMessage(val:
string){ this.message = val; } // template部分 <child :message="message" @onChange="changeMessage" /> // script部分 @Prop() message!: string; public changeMessage(){ this.$emit("onChange", "message"); } Parent.vue Child.vue ・イベント経由で親に”message”を送る ・Propの値は親側で変更する val = ”message”
gettter, setter:Prop値を扱うのに便利 // script部分 public changeMessage(val: string){ this.message = val;
} // template部分 <child @onChange="changeMessage" /> // script部分 @Prop() message!: string; get internalMessage (): string { return this.message; } set internalMessage (val: string) { this.$emit("onChange", val); } Parent.vue Child.vue 子ではinternalMessageを触ればOK
v-model:valueとinputイベントの組み合わせ // script部分 public changeMessage(val: string){ this.message = val; }
// template部分 <child :value="message" @input="changeMessage" /> // script部分 @Prop() value!: string; public changeMessage(val: string){ this.$emit("input", val); } Parent.vue Child.vue ・Propのvalueで受け取り ・emitのinputイベントで親に通知
v-model:valueとinputイベントの組み合わせ // template部分 <child v-model="message" /> // script部分 @Prop()
value!: string; public changeMessage(val: string){ this.$emit("input", val); } Parent.vue Child.vue ・Propのvalueで受け取り ・emitのinputイベントで親に通知 messageの変更イベントを書く 必要もない
配列・オブジェクトの変更 // script部分 messages: string[] = ["test1"]; // template部分 <child
:messages="messages" /> @Prop() messages!: string[]; public changeMessage(): void { // コンソールエラー this.messages = ["書き換え"]; // エラーはないけど変更が検知されない this.messages[0] = "書き換え"; // エラーもなく変更も検知される this.messages.push("追加"); } Parent.vue Child.vue ・配列、オブジェクトの中身は子でも 書き換えできてしまう ・変更を検知させるには配列、オブ ジェクトのメソッドを使うこと
refs:子の要素を触る // script部分 public changeMessage(): void { this.$refs.child.message = "test";
this.$refs.child.changeMessage() } // template部分 <child ref="child" /> <div>{{ $refs.child.message }}</div> // script部分 public message = "子のメッセージ"; public changeMessage(): void { this.message = "書き換え"; } Parent.vue Child.vue ・子どもの変数の書き換えは可能 ・子どものメソッドの実行は可能 参照はできない
まとめ • props:親→子、子で値を触ることはできない • emit:親←子、イベント経由で値を渡せる • getter,setter:Prop値が扱いやすくなる • v-model:valueとinputイベントの組み合わせ •
配列:子から中身は触れる、変更はメソッドを利用する • オブジェクト:配列と同様 • refs:親から子の要素を触れる、参照はできない
ラクスでは定期的にMeetupや 勉強会を開催しています! ご参加お待ちしています! ラクス 中途 フロントエンドエンジニアも募集しています。