* `setup`是一個函數。
* 新的option,所有的組合API函數都在此使用,只在初始化時執行一次。
* 函數如果返回對象,對象中的屬性或方法,模板中可以直接使用。
```html
<template>
<!-- 3. 可以直接在模板中調用number -->
<h1>{{ number }}</h1>
</template>
<script lang="ts">
import { defineComponent } from "vue";
export default defineComponent({
setup() {
// 1. 只在初始化時執行一次
console.log("只執行一次");
return {
// 2. setup返回的對象中放置一個屬性或方法
number: 10,
};
},
});
</script>
```
- nodejs
- 同時安裝多個node版本
- Vue3
- 創建Vue3項目
- 使用 vue-cli 創建
- 使用 vite 創建
- 常用的Composition API
- setup
- ref
- reactive
- 響應數據原理
- setup細節
- reactive與ref細節
- 計算屬性與監視
- 生命周期函數
- toRefs
- 其它的Composition API
- shallowReactive與shallowRef
- readonly與shallowReadonly
- toRaw與markRaw
- toRef
- customRef
- provide與inject
- 響應式數據的判斷
- 組件
- Fragment片斷
- Teleport瞬移
- Suspense
- ES6
- Promise對象
- Promise作用
- 狀態與過程
- 基本使用
- 常用API
- async與await
- Axios