Vue 3 Directory Structure
In the previous chapter we used npm to set up a project (Vue CLI and Vite), and opened the directory in an IDE (VSCode, Atom, etc.). The structure is shown below:
Command-line tool vue-cli (runoob-vue3-test):

Vite (runoob-vue3-test2)

A standard Vue 3 project can usually be split into three layers:
- **Project root:** Build tools and engineering configuration
- **public directory:** Static assets not involved in the build
- **src directory:** Almost all business code lives here; daily development is basically done in this directory.
A typical Vue project structure:
vue-project/
├── public/ # 静态资源,直接复制到构建输出目录
│ └── favicon.ico # 网站图标
├── src/
│ ├── assets/ # 静态资源(如图片、字体、CSS)
│ │ └── logo.png
│ ├── components/ # 可复用的通用组件
│ │ └── CommonHeader.vue
│ ├── composables/ # 可复用的 Composition API 逻辑(可选)
│ │ └── useFetch.js
│ ├── router/ # 路由配置
│ │ └── index.js
│ ├── stores/ # Pinia 状态管理(或 store/ 用于 Vuex)
│ │ └── index.js
│ ├── utils/ # 工具函数(如请求封装、格式化)
│ │ └── request.js
│ ├── views/ # 页面级组件(对应路由页面)
│ │ ├── HomeView.vue
│ │ └── AboutView.vue
│ ├── App.vue # 根组件
│ └── main.js # 入口文件(创建 Vue 应用)
├── index.html # HTML 入口模板
├── vite.config.js # Vite 配置文件
├── package.json # 项目依赖与脚本
├── .gitignore # Git 忽略文件
├── .env # 环境变量(开发)
├── .env.production # 环境变量(生产)
└── README.md # 项目说明
Directory Explanation
| Path | Description |
|---|---|
| public/ | Stores static assets that are not processed by the build tool and are copied directly to the dist directory, commonly used for favicon, robots.txt, etc. |
| public/favicon.ico | Website icon (favicon) |
| src/ | Main directory for project source code; all development code goes here |
| src/assets/ | Stores static assets such as images, fonts, and global CSS; processed by Vite (import supported) |
| src/components/ | Stores reusable common components (such as buttons, cards, layout components) |
| src/composables/ | Stores reusable Composition API logic functions (the code-reuse approach recommended by Vue 3) |
| src/router/ | Vue Router configuration directory, usually containing index.js that defines the route table |
| src/stores/ | Pinia state management directory (officially recommended by Vue 3), storing each store module |
| src/utils/ | Stores utility functions, such as axios wrappers, time formatting, and constants |
| src/views/ | Stores page-level components, usually mapped one-to-one with routes (route pages) |
| src/App.vue | The root component of the Vue application, containing and other entry render points |
| src/main.js | Project entry file; creates the Vue application instance, mounts plugins (router, pinia, etc.), and mounts to #app |
| index.html | HTML template file, containing Mount point |
| vite.config.js | Vite build tool configuration file; allows customizing plugins, aliases, proxies, etc. |
| package.json | Project dependencies and script commands (such as dev, build, preview) |
| .gitignore | Git ignore file, usually ignoring node_modules, dist, .env, etc. |
| .env / .env.production | Environment variable file, used to configure API addresses for different environments (Vite uses variables prefixed with VITE_) |
| README.md | Project documentation |
As the project grows, you may also need to add these folders:
- src/layouts/: Different page layouts (such as AdminLayout.vue, GuestLayout.vue).
- src/plugins/: Custom Vue plugins (such as automatic global component registration).
- src/directives/: Custom directives (such as v-loading).
- src/types/: Global TypeScript type declarations.
- tests/ or tests/: Unit/E2E testing (Vitest + Vue Test Utils).
- src/api/: Separate API interface call modules (more fine-grained than utils/request).
Next, using runoob-vue3-test2 as an example, open the src/APP.vue file in the directory; the code is as follows (explanations are in the comments):
src/APP.vue file code
Next we can try modifying the initialized project by changing src/APP.vue to the following code:
src/APP.vue file code
<
template
<img alt
=
"Vue logo"
src
=
"./assets/logo.png"
/>
<
HelloWorld msg
=
"Welcome to Runoob!"
/>
template
<
script
importHelloWorld from
'./components/HelloWorld.vue'
export
default
{
name
:
'App'
,
components
:
{
HelloWorld
}
}
script
Open the page http://localhost:3000/; generally it refreshes automatically after modification, and the display effect is as follows:
