├── readme.md
├── src
├── content
│ ├── docs
│ │ ├── vue
│ │ │ ├── test
│ │ │ │ └── index.mdx
│ │ │ ├── typescript
│ │ │ │ └── index.mdx
│ │ │ ├── pinia
│ │ │ │ └── index.mdx
│ │ │ ├── others
│ │ │ │ └── index.mdx
│ │ │ ├── hello-world
│ │ │ │ ├── eslint.mdx
│ │ │ │ ├── scss.mdx
│ │ │ │ ├── vite.mdx
│ │ │ │ ├── hello-world.mdx
│ │ │ │ └── structure.mdx
│ │ │ ├── component
│ │ │ │ ├── api.mdx
│ │ │ │ ├── template
│ │ │ │ │ ├── show-if-else.mdx
│ │ │ │ │ ├── html.mdx
│ │ │ │ │ ├── bind.mdx
│ │ │ │ │ ├── event.mdx
│ │ │ │ │ ├── for.mdx
│ │ │ │ │ └── form.mdx
│ │ │ │ ├── sfc.mdx
│ │ │ │ ├── index.mdx
│ │ │ │ └── style.mdx
│ │ │ ├── func
│ │ │ │ ├── lifecycle.mdx
│ │ │ │ ├── methods.mdx
│ │ │ │ └── watch.mdx
│ │ │ ├── index.mdx
│ │ │ ├── data
│ │ │ │ ├── reactivity.mdx
│ │ │ │ ├── data.mdx
│ │ │ │ ├── computed.mdx
│ │ │ │ └── props.mdx
│ │ │ ├── app
│ │ │ │ └── index.mdx
│ │ │ ├── data-transfer
│ │ │ │ ├── attrs.mdx
│ │ │ │ ├── emit.mdx
│ │ │ │ ├── provide-inject.mdx
│ │ │ │ └── slot.mdx
│ │ │ ├── ref
│ │ │ │ └── index.mdx
│ │ │ └── router
│ │ │ │ └── index.mdx
│ │ ├── react
│ │ │ └── index.mdx
│ │ ├── angular
│ │ │ └── index.mdx
│ │ ├── start
│ │ │ ├── knowledge.mdx
│ │ │ ├── env.mdx
│ │ │ └── index.mdx
│ │ ├── topic
│ │ │ ├── component
│ │ │ │ ├── style.mdx
│ │ │ │ ├── func.mdx
│ │ │ │ ├── data.mdx
│ │ │ │ ├── index.mdx
│ │ │ │ └── template.mdx
│ │ │ ├── app
│ │ │ │ └── index.mdx
│ │ │ ├── ref
│ │ │ │ └── index.mdx
│ │ │ ├── hello-world
│ │ │ │ └── index.mdx
│ │ │ └── data-transfer
│ │ │ │ └── index.mdx
│ │ ├── coding-style-guides
│ │ │ ├── index.mdx
│ │ │ ├── common.mdx
│ │ │ ├── javascript.mdx
│ │ │ ├── html.mdx
│ │ │ └── css.mdx
│ │ └── index.mdx
│ └── config.ts
├── assets
│ └── all.jpg
└── env.d.ts
├── tsconfig.json
├── .vscode
├── extensions.json
└── launch.json
├── .gitignore
├── package.json
├── public
└── favicon.svg
├── LICENSE
└── astro.config.mjs
/readme.md:
--------------------------------------------------------------------------------
1 | # Vue、React 和 Angular 一起学怎么样?
2 |
3 | Why not.
4 |
--------------------------------------------------------------------------------
/src/content/docs/vue/test/index.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 测试
3 | ---
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "astro/tsconfigs/strict"
3 | }
--------------------------------------------------------------------------------
/src/content/docs/react/index.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: React
3 | ---
4 |
--------------------------------------------------------------------------------
/src/content/docs/angular/index.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: Angular
3 | ---
4 |
--------------------------------------------------------------------------------
/src/content/docs/vue/typescript/index.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: TypeScript
3 | ---
4 |
--------------------------------------------------------------------------------
/src/assets/all.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LearnShare/learn-VRA/HEAD/src/assets/all.jpg
--------------------------------------------------------------------------------
/src/env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": ["astro-build.astro-vscode"],
3 | "unwantedRecommendations": []
4 | }
5 |
--------------------------------------------------------------------------------
/src/content/docs/vue/pinia/index.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: Pinia - 状态管理
3 | ---
4 |
5 | :::note
6 | Vuex 已经是过去式了,Pinia 是 Vue 当前推荐的状态管理库。
7 | :::
8 |
--------------------------------------------------------------------------------
/src/content/config.ts:
--------------------------------------------------------------------------------
1 | import {
2 | defineCollection,
3 | } from 'astro:content';
4 | import {
5 | docsSchema,
6 | } from '@astrojs/starlight/schema';
7 |
8 | export const collections = {
9 | docs: defineCollection({ schema: docsSchema() }),
10 | };
11 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.2.0",
3 | "configurations": [
4 | {
5 | "command": "./node_modules/.bin/astro dev",
6 | "name": "Development server",
7 | "request": "launch",
8 | "type": "node-terminal"
9 | }
10 | ]
11 | }
12 |
--------------------------------------------------------------------------------
/src/content/docs/vue/others/index.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 其他相关内容
3 | ---
4 |
5 | ## UI 组件库
6 |
7 | + [Element Plus](https://element-plus.org/zh-CN/)
8 |
9 | ## Jamestack
10 |
11 | + [VitePress](https://vitepress.dev/zh/)
12 |
13 | ## 开发框架
14 |
15 | + [Nuxt](https://nuxt.com/)
16 |
--------------------------------------------------------------------------------
/src/content/docs/start/knowledge.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 开始之前
3 | sidebar:
4 | order: 1
5 | ---
6 |
7 | 在开始学习和练习之前,建议您先熟悉前端开发相关的知识,并具有良好的操作技能和学习环境。
8 |
9 | ## 环境和技能
10 |
11 | + 个人电脑:配置开发环境,保存代码和资料
12 | + 通畅的网络:获取信息,下载在线资源
13 | + 英文:阅读文档,查找资料
14 |
15 | ## 前端知识
16 |
17 | + HTML
18 | + CSS
19 | + JavaScript
20 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # build output
2 | dist/
3 | # generated types
4 | .astro/
5 |
6 | # dependencies
7 | node_modules/
8 |
9 | # logs
10 | npm-debug.log*
11 | yarn-debug.log*
12 | yarn-error.log*
13 | pnpm-debug.log*
14 |
15 |
16 | # environment variables
17 | .env
18 | .env.production
19 |
20 | # macOS-specific files
21 | .DS_Store
22 |
--------------------------------------------------------------------------------
/src/content/docs/start/env.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 开发环境
3 | sidebar:
4 | order: 2
5 | ---
6 |
7 | ## 开发工具
8 |
9 | + Node.js
10 | + pnpm
11 | + Visual Studio Code
12 | + Google Chrome
13 | + Git、Github 和 Sourcetree
14 |
15 | ## 库和框架
16 |
17 | + Vue
18 | + React
19 | + Angular
20 |
21 | ## 其他
22 |
23 | + SCSS + dart-sass
24 | + TypeScript
25 | + ESLint
26 |
--------------------------------------------------------------------------------
/src/content/docs/start/index.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 简介
3 | sidebar:
4 | order: 0
5 | ---
6 |
7 | ## 目标
8 |
9 | + 同时学习 Vue、React 和 Angular
10 | + 同步学习三者相同/相关的知识
11 | + 全面切换为 TypeScript
12 | + 融合以往的项目经验
13 | + 尽量涉及更多、更广的内容
14 |
15 | ## 成果记录
16 |
17 | 1. 将学习内容记录到文档中(编写为 Markdown 存放在本项目中)
18 | 2. 将练习代码保存下来(存放在 Github 中,按主题独立分支)
19 |
20 | ## 交流讨论
21 |
22 | + learnshare.hjq#gmail
23 | + [Discord: Learn-VRA](https://discord.gg/vzfFh54322)
24 |
--------------------------------------------------------------------------------
/src/content/docs/topic/component/style.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 样式
3 | sidebar:
4 | order: 2
5 | ---
6 |
7 |
8 |
9 |
10 | | 主题 |
11 | Vue |
12 | React |
13 | Angular |
14 |
15 |
16 |
17 |
18 | | 样式 |
19 |
20 | 样式
21 | |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/content/docs/topic/app/index.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 应用配置和启动
3 | ---
4 |
5 | + 创建应用实例
6 | + 将根组件渲染到 HTML 中
7 | + 通过插件等模块扩展应用
8 |
9 |
10 |
11 |
12 | | 主题 |
13 | Vue |
14 | React |
15 | Angular |
16 |
17 |
18 |
19 |
20 | | 应用配置和启动 |
21 |
22 | Vue 应用
23 | |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "learn-vra",
3 | "type": "module",
4 | "version": "0.0.1",
5 | "private": true,
6 | "scripts": {
7 | "dev": "astro dev",
8 | "start": "astro dev",
9 | "build": "astro check && astro build",
10 | "preview": "astro preview",
11 | "astro": "astro"
12 | },
13 | "dependencies": {
14 | "@astrojs/starlight": "^0.24.2",
15 | "astro": "^4.10.2",
16 | "sharp": "^0.32.5",
17 | "@astrojs/check": "^0.7.0",
18 | "typescript": "^5.4.5"
19 | }
20 | }
--------------------------------------------------------------------------------
/src/content/docs/vue/hello-world/eslint.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: ESLint
3 | ---
4 |
5 | 创建项目时应当已经选择并支持了 ESLint。
6 |
7 | ## 安装 Airbnb 规则
8 |
9 | ``` sh
10 | pnpm i -D eslint-config-airbnb-base
11 | ```
12 |
13 | ## 更新配置文件
14 |
15 | ``` js title=".eslintrc.cjs" ins={2} {5-6}
16 | extends: [
17 | 'airbnb-base',
18 | ],
19 | rules: { // 根据项目风格,设置合适的规则
20 | 'import/no-unresolved': 'off',
21 | 'import/no-extraneous-dependencies': 'off',
22 | },
23 | ```
24 |
25 | ## 运行 ESLint
26 |
27 | 运行 `pnpm run lint`,并根据运行结果修改代码中的问题,或调整 ESLint 规则。
28 |
29 | 可以运行 `pnpm run lint --fix` 自动修复部分问题。
30 |
--------------------------------------------------------------------------------
/src/content/docs/coding-style-guides/index.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 概述
3 | sidebar:
4 | order: 0
5 | ---
6 |
7 | 代码风格(个人总结,仅供参考)。
8 |
9 | ## 目标
10 |
11 | 1. 统一代码风格,提高代码质量
12 | 2. 保证代码易于编写、阅读和维护
13 | 3. 自动化 lint、format
14 |
15 | ## 目录
16 |
17 | 参考资料:
18 |
19 | + [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript)
20 | + [Google Style Guides](http://google.github.io/styleguide/)
21 |
22 | 通用规则:
23 |
24 | + [通用规则](./common)
25 | + HTTP 和 API
26 |
27 | 工具:
28 |
29 | + [EditorConfig](./editor-config)
30 | + JSDoc
31 | + TSDoc
32 | + ESLint
33 |
34 | 按语言:
35 |
36 | + [HTML](./html)
37 | + [CSS](./css)
38 | + [JavaScript](./javascript)
39 |
--------------------------------------------------------------------------------
/src/content/docs/topic/ref/index.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: ref 和 DOM
3 | ---
4 |
5 | 虽然在现代框架中应当尽量避免 DOM 操作,但 DOM 操作是前端开发中无法避免的问题。常见的 DOM 操作场景有:
6 |
7 | + 表单元素的焦点操作
8 | + video/audio 元素的播放控制
9 | + 使用 canvas 元素进行绘图
10 | + 与 jQuery 等 DOM 操作库混合使用
11 |
12 | Vue、React 和 Angular 均提供了引用 DOM 元素的功能,方便进行 DOM 操作。
13 |
14 |
15 |
16 |
17 | | 主题 |
18 | Vue |
19 | React |
20 | Angular |
21 |
22 |
23 |
24 |
25 | | ref 和 DOM |
26 |
27 | 模板引用
28 | |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/public/favicon.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/content/docs/vue/component/api.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: API 风格
3 | ---
4 |
5 | Vue 当前版本提供了两种完全不同的 [API](https://cn.vuejs.org/api/) [风格](https://cn.vuejs.org/guide/introduction.html#api-styles):
6 |
7 | + 选项式 API
8 | + 组合式 API
9 |
10 | ## 选项式 (Options) API
11 |
12 | >自 Vue 诞生时就存在的 API 风格,当前版本(3.*)仍然支持,但选择组合式风格的用户会更多一些。
13 |
14 | 组件的数据和逻辑(甚至是模板)都是选项对象里的参数,它们会暴露在 `this`(指向当前组件实例) 上,可以在模板及函数内使用。
15 |
16 | 参考 [组件 - 组件配置](/vue/component/#组件配置)。
17 |
18 | :::note
19 | 本教程的前半部分仍然以选项式 API 编写,后半部分会完全切换为组合式风格。
20 | :::
21 |
22 | ## 组合式 (Composition) API
23 |
24 | Vue 3 中推出的全新 API 风格([Vue 2.7 也支持了同样的 API](https://v2.cn.vuejs.org/v2/guide/migration-vue-2-7.html))
25 |
26 | 参考 [组合式 API]。
27 |
28 | ## 选择
29 |
--------------------------------------------------------------------------------
/src/content/docs/index.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: Vue、React 和 Angular 一起学怎么样?
3 | description: Get started building your docs site with Starlight.
4 | template: splash
5 | hero:
6 | tagline: Why not.
7 | image:
8 | file: ../../assets/all.jpg
9 | ---
10 |
11 | import {
12 | CardGrid,
13 | LinkCard,
14 | Icon,
15 | } from '@astrojs/starlight/components';
16 |
17 | ## 开始学习
18 |
19 |
20 |
23 |
26 |
29 |
32 |
33 |
--------------------------------------------------------------------------------
/src/content/docs/topic/component/func.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 逻辑
3 | sidebar:
4 | order: 4
5 | ---
6 |
7 |
8 |
9 |
10 | | 主题 |
11 | Vue |
12 | React |
13 | Angular |
14 |
15 |
16 |
17 |
18 | | 逻辑 |
19 |
20 | methods
21 | |
22 |
23 |
24 | |
25 | watch
26 | |
27 |
28 |
29 | |
30 | 生命周期
31 | |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/src/content/docs/vue/hello-world/scss.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: SCSS
3 | ---
4 |
5 | import {
6 | Steps,
7 | } from '@astrojs/starlight/components';
8 |
9 | Vite 已经内置了对 [CSS 预处理器](https://cn.vitejs.dev/guide/features.html#css-pre-processors)的支持,只需要安装相关的依赖即可:
10 |
11 |
12 | 1. 安装 [Dart Sass](https://www.npmjs.com/package/sass):
13 |
14 | ``` sh
15 | pnpm i -D sass
16 | ```
17 |
18 | 2. 添加文件 `components/hello-world.scss`:
19 |
20 | ``` scss title="components/hello-world.scss"
21 | h1 {
22 | color: red;
23 | }
24 | ```
25 |
26 | 3. 在 `hello-world.vue` 末尾添加下面的代码:
27 |
28 | ``` vue title="hello-world.vue" ins={1-4}
29 |
33 | ```
34 |
35 | 4. 运行并检查页面,文字应当显示为**红色**。
36 |
37 |
--------------------------------------------------------------------------------
/src/content/docs/vue/func/lifecycle.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 生命周期
3 | ---
4 |
5 | 参考内容:
6 |
7 | + [Vue Guide: 生命周期图示](https://v3.cn.vuejs.org/guide/instance.html#生命周期图示)
8 | + [Vue API: 生命周期钩子](https://v3.cn.vuejs.org/api/options-lifecycle-hooks.html)
9 |
10 | 生命周期指的是组件运行过程中的特殊时间点,如组件创建、挂载、重新渲染和卸载。
11 |
12 | ## 生命周期钩子
13 |
14 | 生命周期钩子指的是具有特定名称,且会在组件运行的特殊时间点自动执行的方法。
15 |
16 | ``` ts
17 | {
18 | name: 'DemoLifeCycle',
19 |
20 | created() {
21 | // 组件创建并完成初始化
22 | // 可以在这里执行数据初始化,或接口调用
23 | },
24 | mounted() {
25 | // 组件已挂载,但子组件可能没有渲染完毕
26 | // 可以在这里使用 ref 进行 DOM 操作
27 | },
28 | updated() {
29 | // 组件已更新,但子组件可能没有渲染完毕
30 | },
31 | beforeUnmount() {
32 | // 组件卸载之前
33 | // 可以在这里清除定时器和 $watch
34 | },
35 | errorCaptured(error, component, info) {
36 | // 内部组件发生错误
37 | },
38 | }
39 | ```
40 |
--------------------------------------------------------------------------------
/src/content/docs/topic/component/data.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 数据
3 | sidebar:
4 | order: 3
5 | ---
6 |
7 | 数据是组件的核心功能之一。数据具有响应性,它的变化会影响模板的渲染。
8 |
9 |
10 |
11 |
12 | | 主题 |
13 | Vue |
14 | React |
15 | Angular |
16 |
17 |
18 |
19 |
20 | | 数据 |
21 |
22 | 数据的响应性
23 | |
24 |
25 |
26 | |
27 | data
28 | |
29 |
30 |
31 | |
32 | props
33 | |
34 |
35 |
36 | |
37 | computed
38 | |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/content/docs/coding-style-guides/common.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 通用规则
3 | sidebar:
4 | order: 1
5 | ---
6 |
7 | ## 文件和路径
8 |
9 | :::note[DO]
10 | + 项目中的文件存放在同一个目录中
11 | + 使用小写字母和数字
12 | + 使用 `.` 或 `-` 作为单词的连接符
13 | + 路径中始终包含扩展名
14 | :::
15 |
16 | :::danger[DON'T]
17 | + 使用本地绝对路径
18 | :::
19 |
20 | ## 编码
21 |
22 | 使用 UTF-8(no BOM)。
23 |
24 | ## 缩进
25 |
26 | :::note[DO]
27 | + 使用两个或四个空格缩进
28 | :::
29 |
30 | :::danger[DON'T]
31 | + 使用 `Tab` 缩进
32 | + 混合多种缩进方式
33 | :::
34 |
35 | ## 每行字符数
36 |
37 | 每行尽量保持在 80 字符以内,不超过 100 字符。
38 |
39 | ## 行尾空白符
40 |
41 | 行尾不使用任何空白符。
42 |
43 | ## 换行
44 |
45 | + 以保证代码易读为**首要目标**
46 | + 通过缩进表现多行内容的关系
47 | + 使用 Unix [换行](https://zh.wikipedia.org/wiki/%E6%8F%9B%E8%A1%8C)符 LF `\n`
48 |
49 | ## 文件末尾空行
50 |
51 | 文件末尾保留一个空行。
52 |
53 | ## 文件行数
54 |
55 | 每个文件尽量保持在 500 行以内,不超过 1000 行。
56 |
57 | ## 注释
58 |
59 | + 在需要的地方添加注释
60 | + 编写简洁、明确的注释内容
61 |
--------------------------------------------------------------------------------
/src/content/docs/vue/hello-world/vite.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: Vite
3 | ---
4 |
5 | [Vite](https://cn.vitejs.dev/) 是官方推荐的开发工具,它的特点有:
6 |
7 | + [广泛支持](https://github.com/vitejs/vite/tree/main/packages/create-vite) Vue、React 等框架和库
8 | + 基于 ESM,更快的冷启动和热更新
9 |
10 | :::caution
11 | Vue CLI 已经处于维护状态,不推荐在新项目中继续使用。
12 | :::
13 |
14 | ## 创建项目
15 |
16 | ``` sh
17 | pnpm create vue
18 |
19 | # 或使用 Vite 创建
20 | # pnpm create vite
21 | ```
22 |
23 | 根据提示,按需求选择项目配置:
24 |
25 | 1. 项目名称: `vra-vue`
26 | 2. 是否使用 TypeScript: `Yes`
27 | 3. 是否添加 JSX 支持: `No`
28 | 4. 是否添加 Vue Router: `Yes`
29 | 5. 是否使用 Pinia 作为状态管理库: `Yes`
30 | 6. 是否使用 Vitest 作为单元测试库: `Yes`
31 | 7. 选择一个端到端测试方案: `Playwrite`
32 | 8. 是否添加 Vue 开发工具: `Yes`
33 |
34 | ## 运行和预览
35 |
36 | ``` sh
37 | cd vra-vue
38 | pnpm install
39 | pnpm run dev
40 | ```
41 |
42 | 在浏览器中访问 http://localhost:5173/ 即可。
43 |
44 | ## 项目配置文件
45 |
46 | 参考 [配置 Vite](https://cn.vitejs.dev/config/)。
47 |
--------------------------------------------------------------------------------
/src/content/docs/topic/component/index.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 组件
3 | sidebar:
4 | order: 0
5 | ---
6 |
7 | 组件是可复用的模块。它们类似于 HTML 元素,一般包含了下面几个部分:
8 |
9 | + 模板: 包含 HTML 元素或自定义组件,最终渲染为 HTML
10 | + 样式: 最终编译为 CSS,这部分是可选的
11 | + 数据和逻辑: 处理组件数据和交互逻辑的代码
12 |
13 | 关于组件:
14 |
15 | + 组件是应用的基本组成单位。
16 | + 组件内可以包含其他组件,构成组件树。
17 | + 最先渲染到页面中的组件称为**根组件**。
18 |
19 |
20 |
21 |
22 | | 主题 |
23 | Vue |
24 | React |
25 | Angular |
26 |
27 |
28 |
29 |
30 | | 组件 |
31 |
32 | 创建、注册和使用组件
33 | |
34 |
35 |
36 | |
37 | 单文件组件
38 | |
39 |
40 |
41 | |
42 | API 风格
43 | |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/src/content/docs/vue/index.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: Vue
3 | ---
4 |
5 | 核心概念:
6 |
7 | + 开始
8 | + 使用方式
9 | + Vite
10 | + ESLint
11 | + sass
12 | + Hello World
13 | + 发布
14 | + Nuxt
15 | + VitePress
16 | + 应用
17 | + 组件
18 | + 根组件
19 | + 单文件组件
20 | + API 风格
21 | + 选项式
22 | + 组合式
23 | + 组件
24 | + 模板
25 | + HTML 和插值
26 | + 指令 v-*
27 | + 特殊属性
28 | + key
29 | + is
30 | + ref
31 | + 内置元素和组件
32 | + 属性绑定
33 | + 显示或隐藏元素
34 | + 循环
35 | + 事件
36 | + 修饰符
37 | + 表单和双向绑定
38 | + 修饰符
39 | + 样式
40 | + class
41 | + style
42 | + scoped
43 | + CSS Modules
44 | + 数据
45 | + 响应性
46 | + data
47 | + props
48 | + computed
49 | + 逻辑
50 | + methods
51 | + watch
52 | + 生命周期
53 | + ref 和 DOM
54 | + 跨组件数据传递
55 | + 组合式 API
56 | + setup()
57 | + ref()/reactive()
58 | + computed()
59 | + watch()
60 | + 生命周期
61 | + useAttrs()
62 | + 宏/define*
63 | + 复用
64 | + 相关库
65 | + UI 组件
66 | + 状态管理
67 | + 路由
68 | + 测试
69 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Hu Junqing
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/content/docs/topic/hello-world/index.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hello World
3 | ---
4 |
5 | + 了解和安装 cli
6 | + 创建和配置项目
7 | + 认识项目结构
8 | + 编写最小的 Hello World
9 | + 运行和查看
10 |
11 |
12 |
13 |
14 | | 主题 |
15 | Vue |
16 | React |
17 | Angular |
18 |
19 |
20 |
21 |
22 | | 创建和运行项目 |
23 |
24 | Vite
25 | |
26 |
27 |
28 | | 项目结构和配置 |
29 |
30 | 项目结构
31 | |
32 |
33 |
34 | | ESLint + Airbnb |
35 |
36 | ESLint + Airbnb
37 | |
38 |
39 |
40 | | SCSS + dart-sass |
41 |
42 | SCSS + dart-sass
43 | |
44 |
45 |
46 | | Hello World |
47 |
48 | Hello World
49 | |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/src/content/docs/topic/component/template.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 模板
3 | sidebar:
4 | order: 1
5 | ---
6 |
7 |
8 |
9 |
10 | | 主题 |
11 | Vue |
12 | React |
13 | Angular |
14 |
15 |
16 |
17 |
18 | | HTML 和插值 |
19 |
20 | HTML 和插值
21 | |
22 |
23 |
24 | | 属性绑定 |
25 |
26 | 属性绑定
27 | |
28 |
29 |
30 | | 显示或隐藏元素 |
31 |
32 | 显示或隐藏元素
33 | |
34 |
35 |
36 | | 循环 |
37 |
38 | 循环
39 | |
40 |
41 |
42 | | 事件 |
43 |
44 | 事件
45 | |
46 |
47 |
48 | | 表单 |
49 |
50 | 表单和双向绑定
51 | |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/src/content/docs/vue/component/template/show-if-else.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 显示或隐藏元素
3 | ---
4 |
5 | Vue 提供了用于控制元素显示或隐藏的指令。
6 |
7 | ``` vue
8 |
9 | 3. show/hide
10 |
11 | A
13 |
14 | B
16 | B not exist
18 |
19 | C
21 | D
23 | E
25 |
26 |
27 |
28 |
40 | ```
41 |
42 | 渲染出的 HTML:
43 |
44 | ``` html
45 |
46 | A
47 |
48 | B not exist
49 |
50 | D
51 |
52 | ```
53 |
54 | ## v-show
55 |
56 | 从上面的例子可以看出,`v-show` 指令控制了元素是否包含行内样式 `display: none;`,从而控制元素是否显示在页面中。
57 |
58 | ## v-if/v-else-if/v-else
59 |
60 | 与 JavaScript 中的 if/else-if/else 一致,但它们控制元素是否渲染到 HTML 中。
61 |
62 | 当需要通过隐藏元素来控制用户的操作权限时,建议使用 v-if/v-else-if/v-else 从 HTML 中完全移除相应元素。
63 |
--------------------------------------------------------------------------------
/src/content/docs/vue/component/sfc.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 单文件组件
3 | ---
4 |
5 | 单文件组件(Single-File Components, SFC)允许在一处编写模板、样式和脚本代码:
6 |
7 | ``` vue title="src/components/hello-world.vue"
8 |
9 | {{ msg }}
10 |
11 |
12 |
20 |
21 |
26 | ```
27 |
28 | 单文件组件的扩展名通常是 `.vue`,它最终会被编译为 JavaScript 代码,以及额外的 CSS 代码。
29 |
30 | 文件中可以包含三个部分:
31 |
32 | ``` vue
33 |
34 |
35 |
36 |
37 |
40 |
41 |
44 | ```
45 |
46 | ## \
54 | ```
55 |
56 | 在使用其他脚本语言时,需要通过 `lang` 属性指定语言的代号。
57 |
58 | ## \
76 | ```
77 |
--------------------------------------------------------------------------------
/src/content/docs/vue/component/template/html.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: HTML 和插值
3 | ---
4 |
5 | 在 Vue 模板中,几乎可以编写一切符合语法的 HTML 内容。
6 |
7 | 除此之外,Vue 还提供了许多扩展语法。
8 |
9 | ## 插值
10 |
11 | 插值用于将文本内容添加到模板中。
12 |
13 | ``` vue
14 |
15 | 1. HTML
16 | {{ msg }}
17 | a + b = {{ a + b }}
18 |
20 | {{ htmlContent }}
21 |
23 |
24 |
25 |
38 | ```
39 |
40 | 渲染出的 HTML:
41 |
42 | ``` html
43 | 1. HTML
44 | value from data
45 | a + b = 3
46 | value from data
47 | <strong>html content</strong>
48 | html content
49 | ```
50 |
51 | 其中,`{{ msg }}` 将 data.msg 输出为文本内容,并插入到 HTML 中,`v-text="msg"` 的作用是完全一致的。
52 |
53 | 也可以在 `{{ }}` 中编写 JavaScript 语句,语句将完成执行,并输出文本内容。
54 |
55 | 但是无法将包含 HTML 代码的文本直接作为代码插入,它们最终也会输出为文本(`<>` 会被转换为字符实体)。
56 |
57 | ## `v-html` 指令
58 |
59 | 可以使用 `v-html` 指令将 HTML 代码插入到元素中,但需要特别注意这么做是否安全。
60 |
61 | :::note[概念]
62 | [**指令**](https://cn.vuejs.org/api/built-in-directives.html) 是 Vue 提供的特殊属性(attribute),用于在模板中实现诸多功能,通常以 `v-` 作为前缀。
63 | :::
64 |
--------------------------------------------------------------------------------
/src/content/docs/vue/hello-world/hello-world.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hello World
3 | ---
4 |
5 | import {
6 | Steps,
7 | } from '@astrojs/starlight/components';
8 |
9 | ## 编写最小化的 Hello World
10 |
11 | 在上一节完成的代码基础上进行修改:
12 |
13 |
14 | 1. 精简 `hello-world.vue`
15 |
16 | ``` vue title="src/components/hello-world.vue"
17 |
18 | {{ msg }}
19 |
20 |
21 |
29 | ```
30 |
31 | 2. 修改 `app.vue`
32 |
33 | ``` vue title="src/app.vue"
34 |
35 |
36 |
37 |
38 |
48 | ```
49 |
50 | 3. 精简 `main.ts`
51 |
52 | ``` ts title="src/main.ts"
53 | import { createApp } from 'vue';
54 |
55 | import App from './app.vue';
56 |
57 | const app = createApp(App);
58 |
59 | app.mount('#app');
60 | ```
61 |
62 | 4. 删除不相关的文件和目录
63 |
64 | ```
65 | public/
66 | src/components/ (hello-world.vue 以外的文件)
67 | src/assets/
68 | src/router/
69 | src/store/
70 | src/views/
71 | ```
72 |
--------------------------------------------------------------------------------
/src/content/docs/topic/data-transfer/index.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: 跨组件数据传递
3 | ---
4 |
5 | 前面已经了解了跨组件传递数据的几种方式:
6 |
7 | + `props`:可以从父组件向子组件传递各种类型的数据,甚至是方法和组件。
8 | + `$emit`:可以通过事件从子组件向父组件传递数据
9 | + `ref`:可以从父组件中访问子组件的数据或方法。
10 |
11 | 跨组件传递数据的场景有很多:
12 |
13 | + 父组件 \<=> 子组件
14 | + 祖先组件 \<=> 后代组件(跨越多层父子关系)
15 | + 组件 \<=> 兄弟组件(位于同一父组件内)
16 | + 组件树上的任意组件之间(拥有共同的祖先组件)
17 |
18 |
19 |
20 |
21 | | 主题 |
22 | Vue |
23 | React |
24 | Angular |
25 |
26 |
27 |
28 |
29 | | props |
30 |
31 | props
32 | |
33 |
34 |
35 | | attrs |
36 |
37 | attrs
38 | |
39 |
40 |
41 | | slot |
42 |
43 | slot
44 | |
45 |
46 |
47 | | 自定义事件 |
48 |
49 | $emit
50 | |
51 |
52 |
53 | | 局部共享 |
54 |
55 | Provide/Inject
56 | |
57 |
58 |
59 | | 状态管理库 |
60 |
61 | Pinia
62 | |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/src/content/docs/coding-style-guides/javascript.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: JavaScript
3 | ---
4 |
5 | ## 语法特性
6 |
7 | + 优先使用 TypeScript 编写代码
8 | + 优先使用最新的 ECMAScript 语法和特性
9 |
10 | ## 名称
11 |
12 | + 使用有意义的英文单词
13 | + 尽量避免使用数字、空格、连字符(如 `-`、`_`)、缩写、无法阅读和识别的组合(如 `danJia`)、非英文字符(如 `🎶`、`价格`)等
14 | + 变量和字段名称使用 'camelCase' 方式命名
15 | + 模块和类名称使用 'CamelCase' 方式命名
16 |
17 | ## 注释
18 |
19 | + 使用 [JSDoc](https://jsdoc.app/) 或 [TSDoc](https://tsdoc.org/) 语法编写注释内容
20 | + 编写尽量详细的注释
21 |
22 | ## 空格、换行、缩进和标点符号
23 |
24 | + 每行的首尾均不能是空格(以空格缩进的行首除外)
25 | + 关键词、运算符与变量、常量和字面量之间保留一个空格
26 | + 数组和对象
27 | + 尽量将数组和对象拆分为多行书写
28 | + 每行一个成员或属性,以 `,` 结尾,并根据层级向内缩进对应的数量
29 | + 每个 `[` 和 `{` 与之前的内容保持在同一行,在其后换行
30 | + 每个 `]` 和 `}` 在其前换行,并于之后的内容保持在同一行
31 | + 函数
32 | + 声明时,`function funcName() {}` 函数名称与 `()` 之间没有空格
33 | + 匿名函数不论是否有参数,都需要保留 `()`
34 | + 函数参数较多时,可以分为多行编写
35 | + 三目运算符使用换行和缩进区分两个分支
36 | + 连续调用和有多个判断条件时,可以使用缩进区分不同的操作对象和数据比较
37 |
38 | ## 变量、常量和作用域
39 |
40 | + 始终使用 `let` 声明变量,避免使用任何 `var`
41 | + 始终在声明变量时指定初始值
42 | + 仅能将变量赋值为同一类型的数据
43 | + 始终使用 `const` 声明常量
44 | + 每条语句仅能声明一个变量或常量
45 | + 仅在需要的作用域中声明和使用变量和常量
46 | + 尽量避免设置和使用全局变量或常量
47 | + 始终在作用域的顶部完成变量和常量的声明和初始化
48 | + 禁止在同一作用域内重复声明同名的变量或常量
49 |
50 | ## 数据计算和类型比较
51 |
52 | + 仅能计算和比较相同类型的数据
53 | + 多个数据的运算可以使用括号明确优先级
54 | + 禁止使用 `==` 比较数据是否相等
55 | + 比较语句应当是幂等的,禁止任何有副作用的操作
56 |
57 | ## 模块
58 |
59 | + 始终选择 ESM 方案
60 | + 优先导出和使用默认模块
61 |
62 | ## 错误处理
63 |
64 | + 始终编写错误处理逻辑
65 | + 对错误可以选择忽略、重试、备用方案,或者打印日志、提交给统计接口
66 | + 无法处理的错误可以继续抛出,交给其他相关逻辑处理
67 |
68 | ## 格式检查与格式化
69 |
70 | + 应当使用 [ESLint](https://eslint.org/) 进行代码格式检查
71 | + 选择合适且完善的 ESLint 规则
72 | + 尽量避免大规模的自动格式化
73 |
--------------------------------------------------------------------------------
/src/content/docs/vue/func/methods.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: methods - 方法
3 | ---
4 |
5 | 在前面的例子中,我们已经体验了在 Vue 组件中声明和调用方法(或函数):
6 |
7 | ``` ts
8 | import {
9 | defineComponent,
10 | } from 'vue/dist/vue.esm-bundler';
11 |
12 | const ToggleButton = defineComponent({
13 | name: 'toggle-button',
14 | template: `
15 |
17 | `,
18 | data() {
19 | return {
20 | checked: false,
21 | };
22 | },
23 | methods: {
24 | toggleChecked() {
25 | this.checked = !this.checked;
26 | },
27 | },
28 | });
29 |
30 | export default ToggleButton;
31 | ```
32 |
33 | ## 声明方法
34 |
35 | Vue 中的一般方法和事件处理方法都需要写在组件的 `methods` 选项中:
36 |
37 | ``` ts
38 | methods: {
39 | func1() {
40 | this.func2('arg');
41 | },
42 | func2(arg) {
43 | console.log(arg);
44 | },
45 | toggleChecked() {
46 | this.checked = !this.checked;
47 | },
48 | },
49 | ```
50 |
51 | + `methods` 中的方法会自动绑定到组件实例中,通过 `this.funcName()` 访问
52 | + 方法中的 `this` 也指向组件实例
53 | + Vue 不建议在 `methods` 中定义箭头函数 `func3 = () => {}`,这可能会影响 `this` 的指向
54 |
55 | ## 调用方法
56 |
57 | Vue 中调用/使用方法的方式有很多:
58 |
59 | + 作为文本插值
60 |
61 | ``` vue
62 | {{ formatTime(item.createdAt) }}
63 | ```
64 |
65 | + 作为事件处理方法
66 |
67 | ``` vue
68 |