Skip to Content
Vueを学ぶ
book

Vueを学ぶ

by Maya Shavin
March 2025
Intermediate to advanced
350 pages
5h 20m
Japanese
O'Reilly Media, Inc.
Content preview from Vueを学ぶ

第2章. Vueの仕組み:基本

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

前章では、Vueアプリケーションを構築するために不可欠なツールを学び、最初のVueアプリケーションを作成し、次のステップであるVueコードを書いてVueの仕組みを学ぶ準備をした。

この章では、Virtual Document Object Model(Virtual DOM)の概念と、Vue Options APIを使用したVueコンポーネントの書き方の基礎を紹介する。また、VueディレクティブとVueのリアクティビティ機構についても説明する。この章の終わりには、Vueの仕組みを理解し、アプリケーションで使用するVueコンポーネントを書いて登録できるようになる。

仮想DOMの裏側

Vueはドキュメント・オブジェクト・モデル(DOM)を直接操作しない。その代わりに、仮想DOMを実装し、ランタイム におけるアプリケーションのパフォーマンスを最適化する。

仮想DOMがどのように機能するかをしっかり理解するために、まずDOMの概念から始めよう。

DOMは、ウェブ上のHTML(またはXML)文書コンテンツを、インメモリ・ツリー状のデータ構造で表現する(図2-1参照)。DOMはWebページと実際のプログラミングコード(JavaScriptなど)をつなぐプログラミングインタフェースとして機能する。HTML 文書の<div><section> などのタグは、プログラ ミング・ノードやオブジェクト として表現される。

An image illustrated different HTML elements connected, distributing by nesting levels
図2-1. DOMツリーの例

ブラウザがHTMLドキュメントを解析した後、DOMはすぐにインタラクションが可能になる。レイアウトが変更されると、ブラウザはバックグラウンドで常にDOMをペイントし、再ペイントする。私たちは、このプロセスを解析し、DOMをスクリーン・ラスタライズまたはpixel-to-screenパイプラインと呼んでいる。図2-2は、ラスタライズがどのように機能するかを示している :

An image illustrated a flow diagram consisting of five major steps, including parsing HTML and CSS code, calculating the CSS styles for elements, planning for screen layout, then painting the visual elements, and finally applying the composition layer on them on the browsers. It also highlights where repaint and reflow happens whenever layout changes happen.
図2-2. ブラウザのラスタライズ処理

レイアウト更新問題

各ペイントはブラウザのパフォーマンスにとってコストがかかる。DOMは多数のノードで構成されているため、単一ノードや複数ノードのクエリや更新は非常に高価になる可能性がある 。

以下は、DOM内のli 要素のリストの単純な例である:

<ul class="list" id="todo-list">
  <li class="list-item">To do item 1</li>
  <li class="list-item">To do item 2</li>
  <!--so on…-->
</ul>

li 要素の追加・削除や内容の変更には、document.getElementById (またはdocument.getElementsByClassName )を使ってその項目のDOMをクエリする必要がある。その後、適切なDOM APIを使用して必要な更新を実行する必要がある。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

エンジニアが学ぶ会計システムの「知識」と「技術」

エンジニアが学ぶ会計システムの「知識」と「技術」

広川 敬祐, 五島 伸二, 小田 恭彦, 大塚 晃, 川勝 健司
グリーンなソフトウェア開発

グリーンなソフトウェア開発

Anne Currie, Sarah Hsu, Sara Bergman
強力なPython

強力なPython

Aaron Maxwell

Publisher Resources

ISBN: 9798341626102