SlideShare a Scribd company logo
1 of 28
Download to read offline
Vue.js 描画 (render) 関数の紹介

EUSTYLE LABORATORY 

湧上 雄一郎

● はじめに
● なぜこのテーマを選んだか
● render関数とは
● createElement関数とは
● render関数 VS template構文
● 最後に
アジェンダ

はじめに

● render関数って何?という人向けの内容
● まだ学習中のテーマのため、内容が間違っている可能性あり
● 内容が長くなってしまったので早めに進めます
なぜこのテーマを選んだか

なぜこのテーマを選んだか

● メインで関わっている新システム・新規受付フォームの一部コンポーネントで
render関数が使われているから
● 頻繁に使われるものではない、初見だと理解に苦労したため忘備録として
render関数とは

● Vueでは通常コンポーネントを作成する際に、仮想DOMに変換
されるHTMLベースのtemplate構文を使う

● render関数はtemplate構文と役割は同じ。template構文を使わ
ずに直接仮想DOMを生成する

render関数とは

render関数とは

template構文とrender関数の比較

親コンポーネント

子コンポーネント

(テンプレート構文・ render関数)

<h1>Render関数を理解する</h1>

親コンポーネント
template構文とrender関数の比較

Header.vue(template構文)

template構文とrender関数の比較

Header.vue(render関数)

Header.vue(template構文)

template構文とrender関数の比較

Header.vue(render関数)

Header.vue(template構文)

template構文とrender関数の比較

Header.vue(render関数)

<h1>Render関数を理解する</h1>

render関数の基本的な使い方 

● コンポーネントのオブジェクト内にrender関数を用いる 

● 第一引数にcreateElement関数を受け取る 

● createElement関数をリターンするという形で使う 

render関数の基本

createElement関数

createElement関数

・仮想domを出力する時に使う関数

・引数を3つ取れる

render関数

template構文とrender関数の比較

createElement関数

<h1>Render関数を理解する</h1>

createElement関数

実引数hはhyperscriptから来ており、仮想DOMの
実装でよく使われるらしい。仮想DOM界隈ではよく
h を使うことがお決まりになっている。


vue-cli main.js

テンプレート構文とrender関数の比較

違いがよく分からない...

コンポーネントのDOMを動的に変えるように変
更する

levelプロパティの値が1の時

↓

<h1>Render関数を理解する</h1>




levelプロパティの値が2の時

↓

<h2>Render関数を理解する</h2>






テンプレート構文とrender関数の比較

テンプレート構文とrender関数の比較

<h2>Render関数を理解する</h2>

テンプレート構文とrender関数の比較

template構文の苦手箇所
・ディレクティブの属性値と、ムスタッシュ {{}}
でしかJSの式が使えないのでは
・template構文は簡単にかけて便利だが融
通のきかない所がある 

・template構文の苦手なところを補うのが
render関数の役割?

テンプレート構文とrender関数の比較

<h2>Render関数を理解する</h2>

+ 属性
テンプレート構文とrender関数の比較

<h2>Render関数を理解する</h2>

render関数だと全てJSで組みたれてることができる
+ 属性
render関数とは

render関数 VS テンプレート構文

メリット
● 動的にDOMを書けるので描画部分のコードをより簡潔に書け
たり、柔軟に処理を行えたりします。
● 型の恩恵を受けやすい
デメリット
● v-xxx などのVue独自のディレクティブは軒並み利用できなくなりま
す。
● 関数でDOMを組み立てていくので慣れが必要
render関数

render関数 VS テンプレート構文

● template構文では描画ロジックがしんどい時
● JSX・関数型コンポーネントを使いたい時
どのような時にrender関数を使うか

最後に

● render関数の紹介をざっとさせていただきました
● 本当はrender関数と組み合わせて使うJSX、関数型コンポーネントもやりた
かったのですが、時間の都合上難しくかったので興味のある方は公式サイト
をチェックしてみてください

More Related Content

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

2020 06-15 vue.js 描画 (render) 関数の紹介