commit 744026ea2612c0615ec58c88ec7376e2cb8130e9 Author: expressgy Date: Tue Apr 23 00:07:56 2024 +0800 first commit diff --git a/.env b/.env new file mode 100644 index 0000000..0fcc3b6 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +VITE_BASE_URL = "/GY" diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000..b64731a --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,14 @@ +/* eslint-env node */ +require('@rushstack/eslint-patch/modern-module-resolution') + +module.exports = { + root: true, + 'extends': [ + 'plugin:vue/vue3-essential', + 'eslint:recommended', + '@vue/eslint-config-prettier/skip-formatting' + ], + parserOptions: { + ecmaVersion: 'latest' + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8ee54e8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +.DS_Store +dist +dist-ssr +coverage +*.local + +/cypress/videos/ +/cypress/screenshots/ + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +*.tsbuildinfo diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..e40e633 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://json.schemastore.org/prettierrc", + "semi": false, + "tabWidth": 4, + "singleQuote": true, + "printWidth": 100, + "trailingComma": "none" +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..93ea3e7 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "Vue.volar", + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode" + ] +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..39318d7 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# vue3-test + +This template should help get you started developing with Vue 3 in Vite. + +## Recommended IDE Setup + +[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur). + +## Customize configuration + +See [Vite Configuration Reference](https://vitejs.dev/config/). + +## Project Setup + +```sh +npm install +``` + +### Compile and Hot-Reload for Development + +```sh +npm run dev +``` + +### Compile and Minify for Production + +```sh +npm run build +``` + +### Lint with [ESLint](https://eslint.org/) + +```sh +npm run lint +``` diff --git a/docs/学习vue3/vue3.assets/3b3bd03e11464112b94ed3afd66e7fbf.png b/docs/学习vue3/vue3.assets/3b3bd03e11464112b94ed3afd66e7fbf.png new file mode 100644 index 0000000..02820e6 Binary files /dev/null and b/docs/学习vue3/vue3.assets/3b3bd03e11464112b94ed3afd66e7fbf.png differ diff --git a/docs/学习vue3/vue3.assets/48618779e6cc4d9c82bacbc11a59dcae.png b/docs/学习vue3/vue3.assets/48618779e6cc4d9c82bacbc11a59dcae.png new file mode 100644 index 0000000..7cb7a7a Binary files /dev/null and b/docs/学习vue3/vue3.assets/48618779e6cc4d9c82bacbc11a59dcae.png differ diff --git a/docs/学习vue3/vue3.assets/8761f9becf244a3e93973c3a03858dc6.png b/docs/学习vue3/vue3.assets/8761f9becf244a3e93973c3a03858dc6.png new file mode 100644 index 0000000..f0d86ca Binary files /dev/null and b/docs/学习vue3/vue3.assets/8761f9becf244a3e93973c3a03858dc6.png differ diff --git a/docs/学习vue3/vue3.assets/c0eed55cafc0418c813d4a6e77ed2835.png b/docs/学习vue3/vue3.assets/c0eed55cafc0418c813d4a6e77ed2835.png new file mode 100644 index 0000000..0b43181 Binary files /dev/null and b/docs/学习vue3/vue3.assets/c0eed55cafc0418c813d4a6e77ed2835.png differ diff --git a/docs/学习vue3/vue3.assets/d791b0e7431b492b9d5dafe186d884b0.png b/docs/学习vue3/vue3.assets/d791b0e7431b492b9d5dafe186d884b0.png new file mode 100644 index 0000000..7cf6038 Binary files /dev/null and b/docs/学习vue3/vue3.assets/d791b0e7431b492b9d5dafe186d884b0.png differ diff --git a/docs/学习vue3/vue3.assets/ecdb8a0d231140ab8584b83992c41b62.png b/docs/学习vue3/vue3.assets/ecdb8a0d231140ab8584b83992c41b62.png new file mode 100644 index 0000000..4c90fe6 Binary files /dev/null and b/docs/学习vue3/vue3.assets/ecdb8a0d231140ab8584b83992c41b62.png differ diff --git a/docs/学习vue3/vue3.md b/docs/学习vue3/vue3.md new file mode 100644 index 0000000..668930b --- /dev/null +++ b/docs/学习vue3/vue3.md @@ -0,0 +1,910 @@ +# 基础 + +```bash +npm create vue@latest +``` + +## 创建应用 + +### 应用配置 + +> **确保在挂载应用实例之前完成所有应用配置!** + +- 应用级的错误处理器,用来捕获所有子组件上的错误 + +```javascript +app.config.errorHandler = (err) => { + /* 处理错误 */ +} +``` + +- 注册全局资源,**注册一个组件** + +```javascript +app.component('TodoDeleteButton', TodoDeleteButton) +``` + +### 多实例 + +```javascript +const app1 = createApp({ + /* ... */ +}) +app1.mount('#container-1') + +const app2 = createApp({ + /* ... */ +}) +app2.mount('#container-2') +``` + +--- + +## 模板语法 + +> 如果偏好使用JavaScript,JSX 支持直接**手写渲染函数**而不采用模板。但JSX不会享受到和模板同等级别的**编译时优化**。 + +### 文本插值 + +```vue +Message: {{ msg }} +``` + +### 使用原始HTML,不被vue编译 + +```vue +

Using text interpolation: {{ rawHtml }}

+

Using v-html directive:

+``` + +![原始HTML](./vue3.assets/c0eed55cafc0418c813d4a6e77ed2835.png) + +![安全警告](./vue3.assets/3b3bd03e11464112b94ed3afd66e7fbf.png) + +### Attribute 绑定 + +```vue +
+ +
+ + + +
+ + +
+``` + +### _布尔型 Attribute ???_ + +当 isButtonDisabled 为真值或一个空字符串 (即 ` +``` + +### ` + + +``` + +### DOM 更新时机 + +```js +import { nextTick } from 'vue' + +async function increment() { + count.value++ + await nextTick() + // 现在 DOM 已经更新了 +} +``` + +### reactive() + +- `reactive()` 将使对象本身具有响应性 + +```vue + + + + +``` + +- `reactive()` 返回的是一个原始对象的 Proxy + +```js +const raw = {} +const proxy = reactive(raw) + +// 代理对象和原始对象不是全等的 +console.log(proxy === raw) // false + +// 在同一个对象上调用 reactive() 会返回相同的代理 +console.log(reactive(raw) === proxy) // true + +// 在一个代理上调用 reactive() 会返回它自己 +console.log(reactive(proxy) === proxy) // true +``` + +- **这个规则对嵌套对象也适用。依靠深层响应性,响应式对象内的嵌套对象依然是代理:** + +```js +const proxy = reactive({}) + +const raw = {} +proxy.nested = raw + +console.log(proxy.nested === raw) // false +``` + +### `reactive()` 的局限性 + +- 有限的值类型:不能持有如 string、number 或 boolean 这样的原始类型。 + +- 不能替换整个对象: + +```js +let state = reactive({ count: 0 }) + +// 上面的 ({ count: 0 }) 引用将不再被追踪 +// (响应性连接已丢失!) +state = reactive({ count: 1 }) +``` + +- 对解构操作不友好 + +```js +const state = reactive({ count: 0 }) + +// 当解构时,count 已经与 state.count 断开连接 +let { count } = state +// 不会影响原始的 state +count++ + +// 该函数接收到的是一个普通的数字 +// 并且无法追踪 state.count 的变化 +// 我们必须传入整个对象以保持响应性 +callSomeFunction(state.count) +``` + +## 计算属性 + +### 基础示例 + +```vue + + + +``` + +- 计算属性有缓存,当响应值没变化时,计算属性不会执行,如果用函数的话,函数每次都会执行 + +```js +// now永远不会更新,因为他没有用到响应值 +const now = computed(() => Date.now()) +``` + +### 可写计算属性 + +```vue + +``` + +## 类与样式绑定 + +```vue + + +``` + +渲染结果: + +`
` + +### 组件的类会叠加 + +```vue + +

Hi!

+ + + + + +

Hi!

+``` + +## 条件渲染基本没变 + +```vue + +``` + +## 列表渲染 + +### `v-for`可以遍历对象,顺序基于Object.keys() + +### 使用范围值 【整数值】 + +```vue + +{{ n }} +``` + +### `