比如從import { reactive, computed } from 'vue'可以看到,我們常用的API可以有:reactive、computed,那么,你知道vue模塊到底有多少API?事實上它的API還真的不少,高達113個。
你應當首先關注單文件組件開發(fā)下如何使用這些API。
https://v3.cn.vuejs.org/guide/composition-api-setup.html
https://composition-api.vuejs.org/zh/#api-介紹
| 方法/屬性 | 一句話介紹 |
|---|---|
| BaseTransition | |
| Comment | |
| Fragment | |
| KeepAlive | |
| Static | |
| Suspense | |
| Teleport | 傳送到頁面其他位置 |
| Text | |
| Transition | |
| TransitionGroup | |
| callWithAsyncErrorHandling | |
| callWithErrorHandling | |
| camelize | |
| capitalize | |
| cloneVNode | |
| compile$1 as compile | |
| computed$1 as computed | 計算屬性 |
| createApp | 調用 createApp 返回一個應用實例 |
| createBlock | |
| createCommentVNode | |
| createHydrationRenderer | |
| createRenderer | |
| createSSRApp | |
| createSlots | |
| createStaticVNode | |
| createTextVNode | |
| createVNode | |
| customRef | 創(chuàng)建自定義的 ref |
| defineAsyncComponent | |
| defineComponent | 專用于ts的export default defineComponent({}) |
| defineEmit | |
| defineProps | 接收props |
| devtools | |
| getCurrentInstance | 獲取當前實例 |
| getTransitionRawChildren | |
| h | 返回一個”虛擬節(jié)點“,通??s寫為 VNode |
| handleError | |
| hydrate | |
| initCustomFormatter | |
| inject | 接收子孫組件的數(shù)據 |
| isProxy | 檢查對象是否是由 reactive 或 readonly 創(chuàng)建的 proxy。 |
| isReactive | 檢查對象是否是 reactive創(chuàng)建的響應式 proxy。 |
| isReadonly | 檢查對象是否是由readonly創(chuàng)建的只讀 proxy。 |
| isRef | 檢查一個對象是否是Ref對象。 |
| isVNode | |
| markRaw | 標記一個對象,使其永遠不能轉換為 proxy。 |
| mergeProps | |
| nextTick | 同Vue 2 |
| onActivated | 生命周期鉤子 |
| onBeforeMount | 生命周期鉤子 |
| onBeforeUnmount | 生命周期鉤子 |
| onBeforeUpdate | 生命周期鉤子 |
| onDeactivated | 生命周期鉤子 |
| onErrorCaptured | 捕捉子孫組件的錯誤 |
| onMounted | 生命周期鉤子 |
| onRenderTracked | |
| onRenderTriggered | |
| onUnmounted | 生命周期鉤子 |
| onUpdated | 生命周期鉤子 |
| openBlock | |
| popScopeId | |
| provide | 向子孫組件提供數(shù)據 |
| proxyRefs | |
| pushScopeId | |
| queuePostFlushCb | |
| reactive | 等價于 2.x 中的 Vue.observable() API |
| readonly | 只讀 proxy |
| ref | 接受一個內部值并返回一個響應式且可變的 ref 對象 |
| registerRuntimeCompiler | |
| render | |
| renderList | |
| renderSlot | |
| resolveComponent | |
| resolveDirective | |
| resolveDynamicComponent | |
| resolveTransitionHooks | |
| setBlockTracking | |
| setDevtoolsHook | |
| setTransitionHooks | |
| shallowReactive | 創(chuàng)建一個表層響應式 |
| shallowReadonly | 創(chuàng)建一個只讀響應式 |
| shallowRef | 創(chuàng)建一個表層響應式ref |
| ssrContextKey | |
| ssrUtils | |
| toDisplayString | |
| toHandlerKey | |
| toHandlers | |
| toRaw | 返回 reactive 或 readonly proxy 的原始對象 |
| toRef | 只操作一個對象的屬性值 |
| toRefs | toRef的批量版 |
| transformVNodeArgs | |
| triggerRef | 手動執(zhí)行與 shallowRef 關聯(lián)的任何效果 |
| unref | ref的反操作,將Ref對象還原成基礎數(shù)據 |
| useContext | 在setup函數(shù)中使用,獲取上下文 |
| useCssModule | |
| useCssVars | |
| useSSRContext | |
| useTransitionState | |
| vModelCheckbox | |
| vModelDynamic | |
| vModelRadio | |
| vModelSelect | |
| vModelText | |
| vShow | |
| version | |
| warn | |
| watch | 監(jiān)聽器 |
| watchEffect | 監(jiān)聽器 |
| withCtx | |
| withDirectives | |
| withKeys | |
| withModifiers | |
| withScopeId |