Netflix クローンでフロントエンド スキルをレベルアップ
As a developer primarily focused on backend, I've always felt that my frontend skills could use some polishing. To test this, I decided to challenge myself by building a Netflix clone using Vue.js 3 and Vite. In this article, I'll break down the project structure, key components, and share my learning experience.
Project Overview
The goal was to create a responsive web application that mimics the core features of Netflix's user interface. Here's what I initially set out to build:
- A homepage with multiple rows of movies, categorized by genre
- Smooth horizontal scrolling for movie rows
- Lazy loading of images for better performance
- A search functionality to find movies
More to be added in the future.
Tech Stack
For this project, I chose the following tools:
- Vue.js 3: For its reactivity system and component-based architecture
- Vite: As a fast build tool and development server
- Vue Router: For handling navigation
- Pinia: For state management
- Axios: For making API requests to TMDB
- @vueuse/motion: For adding smooth animations
Project Structure
Here's an overview of the project structure:
netflix-clone/ ├── src/ │ ├── components/ │ │ ├── MovieCard.vue │ │ ├── MovieList.vue │ │ ├── MovieRow.vue │ │ └── NavBar.vue │ ├── views/ │ │ ├── HomeView.vue │ │ ├── MovieDetailView.vue │ │ └── SearchView.vue │ ├── router/ │ │ └── index.js │ ├── services/ │ │ └── tmdb.js │ ├── stores/ │ │ └── movies.js │ ├── App.vue │ └── main.js ├── .env.example ├── vite.config.js └── package.json
Key Components Breakdown
MovieCard.vue
This component represents an individual movie. It displays the movie poster and, on hover, shows additional information like the title, rating, and release year.
<template> <div class="movie-card"> <img class="{ lazy" src="/static/imghw/default1.png" data-src="posterUrl" : :alt="Netflix クローンでフロントエンド スキルをレベルアップ" true :loaded imageloaded> <div v-if="isHovered" class="movie-info"> <h3 id="Netflix-クローンでフロントエンド-スキルをレベルアップ">{{ Netflix クローンでフロントエンド スキルをレベルアップ }}</h3> <p>Rating: {{ movie.vote_average }}/10</p> <p>{{ releaseYear }}</p> </div> </div> </template> <script setup> import { ref, computed } from 'vue'; const props = defineProps(['movie']); const imageLoaded = ref(false); const isHovered = ref(false); const posterUrl = computed(() => `https://image.tmdb.org/t/p/w500${props.movie.poster_path}`); const releaseYear = computed(() => new Date(props.movie.release_date).getFullYear()); // ... hover logic </script>
Key learnings:
- Using computed properties for derived data
- Implementing hover effects with CSS transitions
- Lazy loading images for better performance
MovieRow.vue
This component creates a horizontally scrollable row of movies, typically grouped by genre.
<template> <div class="movie-row"> <h2 id="title">{{ title }}</h2> <div class="movie-list" ref="movieList"> <moviecard v-for="movie in movies" :key="movie.id" :movie="movie"></moviecard> </div> <button class="scroll-btn left"><</button> <button @click="scroll('right')" class="scroll-btn right">></button> </div> </template> <script setup> import { ref } from 'vue'; import MovieCard from './MovieCard.vue'; const props = defineProps(['title', 'movies']); const movieList = ref(null); const scroll = (direction) => { const scrollAmount = direction === 'left' ? -300 : 300; movieList.value.scrollBy({ left: scrollAmount, behavior: 'smooth' }); }; </script> ### tmdb.js (API Service) This service handles all API calls to The Movie Database (TMDB) using Axios.
import axios from 'axios'; const API_KEY = import.meta.env.VITE_TMDB_API_KEY; const BASE_URL = 'https://api.themoviedb.org/3'; const tmdbApi = axios.create({ baseURL: BASE_URL, params: { api_key: API_KEY }, }); export const getTrending = () => tmdbApi.get('/trending/all/week'); export const getMoviesByGenre = (genreId) => tmdbApi.get('/discover/movie', { params: { with_genres: genreId } }); export const searchMovies = (query) => tmdbApi.get('/search/movie', { params: { query } });
NavBar.vue
The NavBar component provides navigation for the application and includes a search input for finding movies.
<template> <nav class="navbar"> <router-link to="/" class="navbar-brand">NetflixClone</router-link> <div class="navbar-links"> <router-link to="/">Home</router-link> <div class="search-container"> <input v-model="searchQuery" placeholder="Search movies..."> </div> </div> </nav> </template> <script setup> import { ref } from 'vue'; import { useRouter } from 'vue-router'; import debounce from 'lodash/debounce'; const router = useRouter(); const searchQuery = ref(''); const debounceSearch = debounce(() => { if (searchQuery.value) { router.push({ name: 'search', query: { q: searchQuery.value } }); } }, 300); </script>
HomeView.vue
The HomeView component serves as the main page of the application, displaying multiple MovieRow components with different genres.
<template> <div class="home-view"> <movierow title="Trending" :movies="trendingMovies"></movierow> <movierow v-for="genre in genres" :key="genre.id" :title="genre.name" :movies="moviesByGenre[genre.id]"></movierow> </div> </template> <script setup> import { ref, onMounted } from 'vue'; import MovieRow from '@/components/MovieRow.vue'; import { getTrending, getGenres, getMoviesByGenre } from '@/services/tmdb'; const trendingMovies = ref([]); const genres = ref([]); const moviesByGenre = ref({}); onMounted(async () => { const [trendingResponse, genresResponse] = await Promise.all([ getTrending(), getGenres() ]); trendingMovies.value = trendingResponse.data.results; genres.value = genresResponse.data.genres.slice(0, 5); // Limit to 5 genres for this example for (const genre of genres.value) { const response = await getMoviesByGenre(genre.id); moviesByGenre.value[genre.id] = response.data.results; } }); </script>
SearchView.vue
The SearchView component displays search results based on the user's query.
<template> <div class="search-view"> <h2 id="Search-Results-for-searchQuery">Search Results for "{{ searchQuery }}"</h2> <div class="search-results"> <moviecard v-for="movie in searchResults" :key="movie.id" :movie="movie"></moviecard> </div> </div> </template> <script setup> import { ref, watch } from 'vue'; import { useRoute } from 'vue-router'; import MovieCard from '@/components/MovieCard.vue'; import { searchMovies } from '@/services/tmdb'; const route = useRoute(); const searchQuery = ref(''); const searchResults = ref([]); const performSearch = async () => { const response = await searchMovies(searchQuery.value); searchResults.value = response.data.results; }; watch(() => route.query.q, (newQuery) => { searchQuery.value = newQuery; performSearch(); }, { immediate: true }); </script>
You can find the full source code for this project on GitHub.
以上がNetflix クローンでフロントエンド スキルをレベルアップの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック











さまざまなJavaScriptエンジンは、各エンジンの実装原則と最適化戦略が異なるため、JavaScriptコードを解析および実行するときに異なる効果をもたらします。 1。語彙分析:ソースコードを語彙ユニットに変換します。 2。文法分析:抽象的な構文ツリーを生成します。 3。最適化とコンパイル:JITコンパイラを介してマシンコードを生成します。 4。実行:マシンコードを実行します。 V8エンジンはインスタントコンピレーションと非表示クラスを通じて最適化され、Spidermonkeyはタイプ推論システムを使用して、同じコードで異なるパフォーマンスパフォーマンスをもたらします。

Pythonは、スムーズな学習曲線と簡潔な構文を備えた初心者により適しています。 JavaScriptは、急な学習曲線と柔軟な構文を備えたフロントエンド開発に適しています。 1。Python構文は直感的で、データサイエンスやバックエンド開発に適しています。 2。JavaScriptは柔軟で、フロントエンドおよびサーバー側のプログラミングで広く使用されています。

C/CからJavaScriptへのシフトには、動的なタイピング、ゴミ収集、非同期プログラミングへの適応が必要です。 1)C/Cは、手動メモリ管理を必要とする静的に型付けられた言語であり、JavaScriptは動的に型付けされ、ごみ収集が自動的に処理されます。 2)C/Cはマシンコードにコンパイルする必要がありますが、JavaScriptは解釈言語です。 3)JavaScriptは、閉鎖、プロトタイプチェーン、約束などの概念を導入します。これにより、柔軟性と非同期プログラミング機能が向上します。

Web開発におけるJavaScriptの主な用途には、クライアントの相互作用、フォーム検証、非同期通信が含まれます。 1)DOM操作による動的なコンテンツの更新とユーザーインタラクション。 2)ユーザーエクスペリエンスを改善するためにデータを提出する前に、クライアントの検証が実行されます。 3)サーバーとのリフレッシュレス通信は、AJAXテクノロジーを通じて達成されます。

現実世界でのJavaScriptのアプリケーションには、フロントエンドとバックエンドの開発が含まれます。 1)DOM操作とイベント処理を含むTODOリストアプリケーションを構築して、フロントエンドアプリケーションを表示します。 2)node.jsを介してRestfulapiを構築し、バックエンドアプリケーションをデモンストレーションします。

JavaScriptエンジンが内部的にどのように機能するかを理解することは、開発者にとってより効率的なコードの作成とパフォーマンスのボトルネックと最適化戦略の理解に役立つためです。 1)エンジンのワークフローには、3つの段階が含まれます。解析、コンパイル、実行。 2)実行プロセス中、エンジンはインラインキャッシュや非表示クラスなどの動的最適化を実行します。 3)ベストプラクティスには、グローバル変数の避け、ループの最適化、constとletsの使用、閉鎖の過度の使用の回避が含まれます。

PythonとJavaScriptには、コミュニティ、ライブラリ、リソースの観点から、独自の利点と短所があります。 1)Pythonコミュニティはフレンドリーで初心者に適していますが、フロントエンドの開発リソースはJavaScriptほど豊富ではありません。 2)Pythonはデータサイエンスおよび機械学習ライブラリで強力ですが、JavaScriptはフロントエンド開発ライブラリとフレームワークで優れています。 3)どちらも豊富な学習リソースを持っていますが、Pythonは公式文書から始めるのに適していますが、JavaScriptはMDNWebDocsにより優れています。選択は、プロジェクトのニーズと個人的な関心に基づいている必要があります。

開発環境におけるPythonとJavaScriptの両方の選択が重要です。 1)Pythonの開発環境には、Pycharm、Jupyternotebook、Anacondaが含まれます。これらは、データサイエンスと迅速なプロトタイピングに適しています。 2)JavaScriptの開発環境には、フロントエンドおよびバックエンド開発に適したnode.js、vscode、およびwebpackが含まれます。プロジェクトのニーズに応じて適切なツールを選択すると、開発効率とプロジェクトの成功率が向上する可能性があります。
