Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Vue 3 Blog Project

Vue 3 Blog Project

This chapter takes you from scratch to create a Vue 3 blog project with Vite and understand the role of each file in the project.


Environment Preparation

Before starting, make sure Node.js is installed on your computer.

Node.js is the JavaScript runtime environment that lets us run JS code outside the browser.

The Vue 3 development toolchain (Vite, npm) depends on Node.js.

Check If Node.js Is Installed

Open a terminal (CMD or PowerShell on Windows, Terminal on Mac) and enter the following command:



$ node -v

v20.10.0

If a version number is displayed (v16 or above recommended), it means it is installed.

If not, go to nodejs.org and download the LTS version to install.

npm (Node Package Manager) is bundled automatically when installing Node.js.

Verification command:

npm -v

Create a Vue 3 Project

The Vue official team recommends using the create-vue scaffolding tool to initialize the project.

In the terminal, navigate to the directory where you want to store the project and run:



npm create vue@latest blog-app

After running, a series of options appears; choose as follows:

Option Choice Description
Add TypeScript? No Beginners should start with plain JS
Add JSX Support? No Template syntax is more intuitive
Add Vue Router? Yes Routing will be used later
Add Pinia? Yes State management, used later
Add Vitest? No Tests not needed for now
Add ESLint? No Beginners can skip for now

After completing the selection, run the following in order as prompted:



$ cd blog-app

$ npm install

$ npm run dev

The browser will automatically open http://localhost:5173 and show Vue's default welcome page, indicating the project started successfully.

npm install downloads all dependency packages to the node_modules directory based on package.json; this step requires internet and may take a few minutes the first time.


Detailed Project Directory Structure

Open the blog-app folder and you will see the following structure:



blog-app/

├── index.html              # 入口 HTML 文件

├── package.json            # 项目配置与依赖列表

├── vite.config.js          # Vite 构建工具配置

├── public/                 # 不经过编译的静态资源

├── src/

│   ├── main.js             # JS 入口,创建并挂载 Vue 应用

│   ├── App.vue             # 根组件,所有页面的外壳

│   ├── assets/             # 需要编译的静态资源(CSS、图片)

│   ├── components/         # 可复用的 Vue 组件

│   ├── views/              # 页面级组件(路由对应的页面)

│   ├── router/             # 路由配置

│   └── stores/             # Pinia 状态管理

Roles of Core Files

index.html — The entry file accessed by the browser.

Vite automatically injects src/main.js into this file; you don't need to manually import any JS.

src/main.js — The startup file of the Vue application.

It is responsible for creating the Vue application instance, registering plugins (routing, state management), and mounting the application to the HTML page.

src/App.vue — The root component.

It is the outermost container of all pages, usually containing the navbar, footer, and router outlet.


Single File Component (SFC)

In Vue, every .vue file is called a "Single File Component" (SFC).

It encapsulates a component's template, logic, and styles together; one file is an independent functional unit.

The Three-Section SFC Structure

Example

The order of these three tags can be arbitrary, but the industry convention is: script → template → style.

Section Purpose One-Sentence Understanding

After saving, the browser refreshes automatically, and you will see a clean blog skeleton: top navbar + middle content area + bottom footer.

This is the starting point for all subsequent chapters.


Chapter Summary

In this chapter you accomplished three things: created a Vue 3 project with Vite, understood the directory structure and the three-section SFC, and wrote the blog's basic HTML skeleton.

Key takeaway: understand that a .vue file consists of three parts — template / script / style — and how to get a Vue project running.