漸進式 JavaScript 框架 備忘清單的快速參考列表,包含常用 API 和示例
Vue 是一套用于構建用戶界面的漸進式框架
注意:Vue 3.x 版本對應 Vue Router 4.x 路由版本
已安裝 16.0
或更高版本的 Node.js
$ npm init vue@latest
指令將會安裝并執行 ,它是 Vue 官方的項目腳手架工具
? Project name: … <your-project-name>
? Add TypeScript? … No/Yes
? Add JSX Support? … No/Yes
? Add Vue Router for Single Page Application development? … No/Yes
? Add Pinia for state management? … No/Yes
? Add Vitest for Unit testing? … No/Yes
? Add Cypress for both Unit and End-to-End testing? … No/Yes
? Add ESLint for code quality? … No/Yes
? Add Prettier for code formatting? … No/Yes
Scaffolding project in ./<your-project-name>...
Done.
安裝依賴并啟動開發服務器
$ cd <your-project-name>
$ npm install
$ npm run dev
當你準備將應用發布到生產環境時,請運行:
$ npm run build
此命令會在 ./dist
文件夾中為你的應用創建一個生產環境的構建版本
import { createApp, ref } from 'vue'
const app = createApp({
setup() {
const message = ref("Hello Vue3")
return {
message
}
}
})
app.mount('#app')
掛載應用
<div id="app">
<button @click="count++">
{{ count }}
</button>
</div>
<script src="//unpkg.com/vue@3/dist/vue.global.js"></script>
<div id="app">{{ message }}</div>
<script>
const { createApp, ref } = Vue
createApp({
setup() {
const message = ref("Hello Vue3")
return {
message
}
}
}).mount('#app')
</script>
<div id="app">{{ message, ref }}</div>
<script type="module">
import { createApp, ref } from '//unpkg.com/vue@3/dist/vue.esm-browser.js'
createApp({
setup() {
const message = ref("Hello Vue3")
return {
message
}
}
}).mount('#app')
</script>
<span>Message: {{ msg }}</span>
使用的是 Mustache
語法 (即雙大括號),每次 msg
屬性更改時它也會同步更新
<p>Using text interpolation: {{ rawHtml }}</p>
<p>Using v-html directive: <span v-html="rawHtml"></span></p>
雙大括號{{}}
會將數據解釋為純文本,使用 v-html
指令,將插入 HTML
<div v-bind:id="dynamicId"></div>
簡寫
<div :id="dynamicId"></div>
<button :disabled="isButtonDisabled">
Button
</button>
通過不帶參數的 v-bind
,你可以將它們綁定到單個元素上
<script setup>
import comp from "./Comp.vue"
import {ref} from "vue"
const a = ref("hello")
const b = ref("world")
</script>
<template>
<comp v-bind="{a, b}"></comp>
</template>
如果你是使用的 setup
語法糖。需要使用 defineprops
聲名(可以直接使用a
/b
)
const props = defineProps({
a: String,
b: String
})
{{ number + 1 }}
{{ ok ? 'YES' : 'NO' }}
{{ message.split('').reverse().join('') }}
<div :id="`list-${id}`"></div>
<!-- 這是一個語句,而非表達式 -->
{{ var a = 1 }}
<!-- 條件控制也不支持,請使用三元表達式 -->
{{ if (ok) { return message } }}
<span :title="toTitleDate(date)">
{{ formatDate(date) }}
</span>
<p v-if="seen">Now you see me</p>
<a v-bind:href="url"> ... </a>
<!-- 簡寫 -->
<a :href="url"> ... </a>
<a v-on:click="doSomething"> ... </a>
<!-- 簡寫 -->
<a @click="doSomething"> ... </a>
<a v-bind:[attributeName]="url"> ... </a>
<!-- 簡寫 -->
<a :[attributeName]="url"> ... </a>
這里的 attributeName
會作為一個 JS 表達式被動態執行
<a v-on:[eventName]="doSomething"> ... </a>
<!-- 簡寫 -->
<a @[eventName]="doSomething">
<form @submit.prevent="onSubmit">
...
</form>
.prevent
修飾符會告知 v-on
指令對觸發的事件調用 event.preventDefault()
v-on:submit.prevent="onSubmit"
──┬─ ─┬──── ─┬───── ─┬──────
┆ ┆ ┆ ╰─ Value 解釋為JS表達式
┆ ┆ ╰─ Modifiers 由前導點表示
┆ ╰─ Argument 跟隨冒號或速記符號
╰─ Name 以 v- 開頭使用速記時可以省略
<div>{{ state.count }}</div>
import { defineComponent, reactive } from 'vue';
// `defineComponent`用于IDE推導類型
export default defineComponent({
// setup 用于組合式 API 的特殊鉤子函數
setup() {
const state = reactive({ count: 0 });
// 暴露 state 到模板
return {
state
};
},
});
<button @click="increment">
{{ state.count }}
</button>
import { defineComponent, reactive } from 'vue';
export default defineComponent({
setup() {
const state = reactive({ count: 0 });
function increment() {
state.count++;
}
// 不要忘記同時暴露 increment 函數
return {
state,
increment
};
},
})
<script setup>
setup語法糖<script setup>
import { reactive } from 'vue';
const state = reactive({ count: 0 })
function increment() {
state.count++
}
</script>
<template>
<button @click="increment">
{{ state.count }}
</button>
</template>
setup
語法糖用于簡化代碼,尤其是當需要暴露的狀態和方法越來越多時
ref()
定義響應式變量reactive
只能用于對象、數組和 Map
、Set
這樣的集合類型,對 string、number 和 boolean 這樣的原始類型則需要使用ref
import { ref } from 'vue';
const count = ref(0);
console.log(count); // { value: 0 }
console.log(count.value); // 0
count.value++;
console.log(count.value); // 1
const objectRef = ref({ count: 0 });
// 這是響應式的替換
objectRef.value = { count: 1 };
const obj = {
foo: ref(1),
bar: ref(2)
};
// 該函數接收一個 ref
// 需要通過 .value 取值
// 但它會保持響應性
callSomeFunction(obj.foo);
// 仍然是響應式的
const { foo, bar } = obj;
在 html 模板中不需要帶 .value
就可以使用
<script setup>
import { ref } from 'vue';
const count = ref(0);
</script>
<template>
<div>
{{ count }}
</div>
</template>
import { reactive, defineComponent, onUnmounted } from 'vue';
import { debounce } from 'lodash-es';
export default defineComponent({
setup() {
// 每個實例都有了自己的預置防抖的處理函數
const debouncedClick = debounce(click, 500);
function click() {
// ... 對點擊的響應 ...
}
// 最好是在組件卸載時
// 清除掉防抖計時器
onUnmounted(() => {
debouncedClick.cancel();
});
},
});
<script setup>
import { ref } from 'vue'
const open = ref(false);
</script>
<template>
<button @click="open = !open">Toggle</button>
<div>Hello Vue!</div>
</template>
<style scope>
div{
transition: height 0.1s linear;
overflow: hidden;
height: v-bind(open ? '30px' : '0px');
}
</style>
<script setup>
import { ref, watch } from 'vue';
const count = ref(0)
const isEvent = ref(false)
function increment() {
state.count++
}
watch(count, function() {
isEvent.value = count.value % 2 === 0
})
</script>
<template>
<button @click="increment">
{{ count }}
</button>
<p>
is event: {{ isEvent ? 'yes' : 'no' }}
</p>
</template>
watch(count, function() {
isEvent.value = count.value % 2 === 0
}, {
// 上例中的 watch 不會立即執行,導致 isEvent 狀態的初始值不準確。配置立即執行,會在一開始的時候立即執行一次
immediate: true
})
<script setup>
import { ref, computed } from 'vue';
const text = ref('')
// computed 的回調函數里,會根據已有并用到的狀態計算出新的狀態
const capital = computed(function(){
return text.value.toUpperCase();
})
</script>
<template>
<input v-model="text" />
<p>to capital: {{ capital }}</p>
</template>
<script setup>
import { defineProps } from 'vue';
// 這里可以將 `username` 解構出來,
// 但是一旦解構出來再使用,就不具備響應式能力
defineProps({
username: String
})
</script>
<template>
<p>username: {{ username }}</p>
</template>
子組件定義需要的參數
<script setup>
const username = 'vue'
</script>
<template>
<children :username="username" />
</template>
父組件參入參數
<script setup>
import { defineEmits, ref } from 'vue';
const emit = defineEmits(['search'])
const keyword = ref('')
const onSearch = function() {
emit('search', keyword.value)
}
</script>
<template>
<input v-model="keyword" />
<button @click="onSearch">search</button>
</template>
子組件定義支持 emit
的函數
<script setup>
const onSearch = function(keyword){
console.log(keyword)
}
</script>
<template>
<children @search="onSearch" />
</template>
父組件綁定子組件定義的事件
<script setup>
import { defineExpose, ref } from 'vue';
const keyword = ref('')
const onSearch = function() {
console.log(keyword.value)
}
defineExpose({ onSearch })
</script>
<template>
<input v-model="keyword" />
</template>
子組件對父組件暴露方法
<script setup>
import { ref } from 'vue'
const childrenRef = ref(null)
const onSearch = function() {
childrenRef.value.onSearch()
}
</script>
<template>
<children ref='childrenRef' />
<button @click="onSearch">search</button>
</template>
父組件調用子組件的方法
import type { InjectionKey, Ref } from 'vue'
export const ProvideKey = Symbol() as InjectionKey<Ref<string>>
在應用中使用 ProvideKey
<script setup lang="ts">
import { provide, ref } from 'vue'
import { ProvideKey } from './types'
const text = ref<string>('123')
provide(ProvideKey, text)
</script>
<template>
<input v-model="text" />
</template>
父組件為后代組件提供數據
<script setup lang="ts">
import { inject } from 'vue'
import { ProvideKey } from './types'
const value = inject(ProvideKey)
</script>
<template>
<h4>{{value}}</h4>
</template>
后代組件注入父組件提供的數據
當使用 <script setup>
時,defineProps()
宏函數支持從它的參數中推導類型
<script setup lang="ts">
const props = defineProps({
foo: { type: String, required: true },
bar: Number
})
props.foo // string
props.bar // number | undefined
</script>
對同一個文件中的一個接口或對象類型字面量的引用:
interface Props {/* ... */}
defineProps<Props>()
export interface Props {
msg?: string
labels?: string[]
}
const props = withDefaults(defineProps<Props>(), {
msg: 'hello',
labels: () => ['one', 'two']
})
使用目前為實驗性的響應性語法糖
<script setup lang="ts">
interface Props {
name: string
count?: number
}
// 對 defineProps() 的響應性解構
// 默認值會被編譯為等價的運行時選項
const {
name, count = 100
} = defineProps<Props>()
</script>
<script setup lang="ts">
// 運行時
const emit = defineEmits(['change', 'update'])
// 基于類型
const emit = defineEmits<{
(e: 'change', id: number): void
(e: 'update', value: string): void
}>()
</script>
ref 會根據初始化時的值推導其類型:
import { ref } from 'vue'
import type { Ref } from 'vue'
const year: Ref<string | number> = ref('2020')
year.value = 2020 // 成功!
import { reactive } from 'vue'
interface Book {
title: string
year?: number
}
const book: Book = reactive({
title: 'Vue 3 指引'
})
你還可以通過泛型參數顯式指定類型:
const double = computed<number>(() => {
// 若返回值不是 number 類型則會報錯
})
<script setup lang="ts">
function handleChange(event) {
// `event` 隱式地標注為 `any` 類型
console.log(event.target.value)
}
</script>
<template>
<input
type="text"
@change="handleChange" />
</template>
顯式地為事件處理函數的參數標注類型
function handleChange(event: Event) {
const target = event.target as HTMLInputElement
console.log(target.value)
}
import { provide, inject } from 'vue'
import type { InjectionKey } from 'vue'
const key = Symbol() as InjectionKey<string>
// 若提供的是非字符串值會導致錯誤
provide(key, 'foo')
// foo 的類型:string | undefined
const foo = inject(key)
<script setup lang="ts">
import { ref, onMounted } from 'vue'
const el = ref<HTMLInputElement | null>(null)
onMounted(() => {
el.value?.focus()
})
</script>
<template>
<input ref="el" />
</template>
<!-- MyModal.vue -->
<script setup lang="ts">
import { ref } from 'vue'
const isContentShown = ref(false)
const open =
() => (isContentShown.value = true)
defineExpose({
open
})
</script>
使用 TypeScript 內置的 InstanceType
工具類型來獲取其實例類
<!-- App.vue -->
<script setup lang="ts">
import MyModal from './MyModal.vue'
type Modal = InstanceType<typeof MyModal>
const modal = ref<Modal | null>(null)
const openModal = () => {
modal.value?.open()
}
</script>
import { defineComponent } from 'vue'
export default defineComponent({
// 啟用了類型推導
props: {
name: String,
id: [Number, String],
msg: { type: String, required: true },
metadata: null
},
mounted() {
// 類型:string | undefined
this.name
// 類型:number|string|undefined
this.id
// 類型:string
this.msg
// 類型:any
this.metadata
}
})
使用 PropType 這個工具類型來標記更復雜的 props 類型
import { defineComponent } from 'vue'
import type { PropType } from 'vue'
interface Book {
title: string
author: string
year: number
}
export default defineComponent({
props: {
book: {
// 提供相對 `Object` 更確定的類型
type: Object as PropType<Book>,
required: true
},
// 也可以標記函數
callback: Function as PropType<(id: number) => void>
},
mounted() {
this.book.title // string
this.book.year // number
// TS Error: argument of type 'string' is not
// assignable to parameter of type 'number'
this.callback?.('123')
}
})
import { defineComponent } from 'vue'
type Payload = { bookName: string }
export default defineComponent({
emits: {
addBook(payload: Payload) {
// 執行運行時校驗
return payload.bookName.length > 0
}
},
methods: {
onSubmit() {
this.$emit('addBook', {
bookName: 123 // 類型錯誤
})
// 類型錯誤
this.$emit('non-declared-event')
}
}
})
計算屬性會自動根據其返回值來推導其類型:
import { defineComponent } from 'vue'
export default defineComponent({
data() {
return {
message: 'Hello!'
}
},
computed: {
greeting() {
return this.message + '!'
}
},
mounted() {
this.greeting // 類型:string
}
})
在某些場景中,你可能想要顯式地標記出計算屬性的類型以確保其實現是正確的:
import { defineComponent } from 'vue'
export default defineComponent({
data() {
return {
message: 'Hello!'
}
},
computed: {
// 顯式標注返回類型
greeting(): string {
return this.message + '!'
},
// 標注一個可寫的計算屬性
greetingUppercased: {
get(): string {
return this.greeting.toUpperCase()
},
set(newValue: string) {
this.message = newValue.toUpperCase()
}
}
}
})
import { defineComponent } from 'vue'
export default defineComponent({
methods: {
handleChange(event: Event) {
console.log((event.target as HTMLInputElement).value)
}
}
})
import axios from 'axios'
declare module 'vue' {
interface ComponentCustomProperties {
$http: typeof axios
$translate: (key: string) => string
}
}
我們可以將這些類型擴展放在一個 .ts
文件,或是一個影響整個項目的 *.d.ts
文件中
// 不工作,將覆蓋原始類型。
declare module 'vue' {
interface ComponentCustomProperties {
$translate: (key: string) => string
}
}
// 正常工作。
export {}
declare module 'vue' {
interface ComponentCustomProperties {
$translate: (key: string) => string
}
}
某些插件,比如 vue-router,提供了一些自定義的組件選項,比如 beforeRouteEnter:
import { defineComponent } from 'vue'
export default defineComponent({
beforeRouteEnter(to, from, next) {
// ...
}
})
如果沒有確切的類型標注,這個鉤子函數的參數會隱式地標注為 any
類型。我們可以為 ComponentCustomOptions
接口擴展自定義的選項來支持:
import { Route } from 'vue-router'
declare module 'vue' {
interface ComponentCustomOptions {
beforeRouteEnter?(
to: Route,
from: Route,
next: () => void
): void
}
}
:- | :- |
---|---|
createApp() | 創建一個應用實例 |
createSSRApp() | 以 模式創建一個應用實例 |
app.mount() | 將應用實例掛載在一個容器元素中 |
app.unmount() | 卸載一個已掛載的應用實例 |
app.provide() | 提供一個可以在應用中的所有后代組件中注入使用的值 |
app.component() | 注冊或獲取全局組件 |
app.directive() | 注冊或獲取全局指令 |
app.use() | 安裝一個插件 |
app.mixin() | 全局注冊一個混入 |
app.version | 當前應用所使用的 Vue 版本號 |
app.config | 獲得應用實例的配置設定 |
app.config.errorHandler | 為應用內拋出的未捕獲錯誤指定一個全局處理函數 |
app.config.warnHandler | 為 Vue 的運行時警告指定一個自定義處理函數 |
app.config.performance | 在瀏覽器開發工具中追蹤性能表現 |
app.config.compilerOptions | 配置運行時編譯器的選項 |
app.config.globalProperties | 注冊全局屬性對象 |
app.config.optionMergeStrategies | 定義自定義組件選項的合并策略的對象 |
:- | :- |
---|---|
version | Vue 版本號 |
nextTick() | 等待下一次 DOM 更新后執行回調 |
defineComponent() | 在定義 Vue 組件時提供類型推導的輔助函數 |
defineAsyncComponent() | 定義一個異步組件 |
defineCustomElement() | 和 defineComponent 接受的參數相同,不同的是會返回一個原生自定義元素類的構造器 |
:- | :- |
---|---|
基本使用 | |
訪問 Props | |
Setup 上下文 | |
與渲染函數一起使用 |
:- | :- |
---|---|
provide() | 提供一個可以被后代組件中注入使用的值 |
inject() | 注入一個由祖先組件提供的值 |
:- | :- |
---|---|
onMounted() | 組件掛載完成后執行 |
onUpdated() | 狀態變更而更新其 DOM 樹之后調用 |
onUnmounted() | 組件實例被卸載之后調用 |
onBeforeMount() | 組件被掛載之前被調用 |
onBeforeUpdate() | 狀態變更而更新其 DOM 樹之前調用 |
onBeforeUnmount() | 組件實例被卸載之前調用 |
onErrorCaptured() | 捕獲了后代組件傳遞的錯誤時調用 |
onRenderTracked() | 組件渲染過程中追蹤到響應式依賴時調用 |
onRenderTriggered() | 響應式依賴的變更觸發了組件渲染時調用 |
onActivated() | 若組件實例是 <KeepAlive> 緩存樹的一部分,當組件被插入到 DOM 中時調用 |
onDeactivated() | 若組件實例是 <KeepAlive> 緩存樹的一部分,當組件從 DOM 中被移除時調用 |
onServerPrefetch() | 組件實例在服務器上被渲染之前調用 |
:- | :- |
---|---|
isRef() | 判斷是否為 ref |
unref() | 是 ref,返回內部值,否則返回參數本身 |
toRef() | 創建一個屬性對應的 ref |
toRefs() | 將對象上的每一個可枚舉屬性轉換為 ref |
isProxy() | 檢查一個對象是否是由 reactive() 、readonly() 、shallowReactive() 或 shallowReadonly() 創建的代理 |
isReactive() | 檢查一個對象是否是由 reactive() 或 shallowReactive() 創建的代理。 |
isReadonly() | 檢查傳入的值是否為只讀對象 |
:- | :- |
---|---|
ref() | 返回一個 ref 對象 |
computed () | 定義一個計算屬性 |
reactive() | 返回一個對象的響應式代理 |
readonly() | 返回一個原值的只讀代理 |
watchEffect() | 立即運行一個函數,同時監聽 |
watchPostEffect() | watchEffect() 使用 flush: 'post' 選項時的別名。 |
watchSyncEffect() | watchEffect() 使用 flush: 'sync' 選項時的別名。 |
watch() | 偵聽一個或多個響應式數據源 |
:- | :- |
---|---|
data | 聲明組件初始響應式狀態 |
props | 聲明一個組件的 props |
computed | 聲明要在組件實例上暴露的計算屬性 |
methods | 聲明要混入到組件實例中的方法 |
watch | 聲明在數據更改時調用的偵聽回調 |
emits | 聲明由組件觸發的自定義事件 |
expose | 聲明當組件實例被父組件通過模板引用訪問時暴露的公共屬性 |
:- | :- |
---|---|
beforeCreate | 組件實例初始化完成之后立即調用 |
created | 組件實例處理完所有與狀態相關的選項后調用 |
beforeMount | 組件被掛載之前調用 |
mounted | 組件被掛載之后調用 |
beforeUpdate | 狀態變更而更新其 DOM 樹之前調用 |
updated | 狀態變更而更新其 DOM 樹之后調用 |
beforeUnmount | 組件實例被卸載之前調用 |
unmounted | 組件實例被卸載之后調用 |
errorCaptured | 捕獲了后代組件傳遞的錯誤時調用 |
renderTracked Dev only | 組件渲染過程中追蹤到響應式依賴時調用 |
renderTriggered Dev only | 響應式依賴的變更觸發了組件渲染時調用 |
activated | 若組件實例是 |
deactivated | 若組件實例是 |
serverPrefetch SSR only | 組件實例在服務器上被渲染之前調用 |
:- | :- |
---|---|
name | 顯式聲明組件展示時的名稱 |
inheritAttrs | 是否啟用默認的組件 attribute 透傳行為 |
components | 注冊對當前組件實例可用的組件 |
directives | 注冊對當前組件實例可用的指令 |
:- | :- |
---|---|
template | 聲明組件的字符串模板 |
render | 編程式地創建組件虛擬 DOM 樹的函數 |
compilerOptions | 配置組件模板的運行時編譯器選項 |
:- | :- |
---|---|
$data | 觀察的數據對象 |
$props | 組件已解析的 props 對象 |
$el | 實例管理的 DOM 根節點 |
$options | 實例的初始化選項 |
$parent | 父實例 |
$root | 當前組件樹的根實例 |
$slots | 訪問被插槽分發的內容 |
$refs | DOM 元素和組件實例 |
$attrs | 包含了組件所有 |
$watch() | 觀察 Vue 實例上的一個表達式或者一個函數計算結果的變化 |
$emit() | 觸發一個自定義事件 |
$forceUpdate() | 強制該組件重新渲染 |
$nextTick() | 回調延遲執行 |
:- | :- |
---|---|
provide | 提供可以被后代組件注入的值 |
inject | 注入一個由祖先組件提供的值 |
mixins | 接收一個混入對象的數組 |
extends | 要繼承的“基類”組件 |
:- | :- |
---|---|
v-text | 更新元素的 textContent |
v-html | 更新元素的 innerHTML |
v-show | 切換元素的 display css 屬性 |
v-if | 有條件地渲染元素 |
v-else | |
v-else-if | |
v-for | 多次渲染元素或模板塊 |
v-on | 綁定事件監聽器 |
v-bind | 動態地綁定一個或多個屬性 |
v-model | 創建雙向綁定 |
v-slot | 提供插槽或接收 props 的插槽 |
v-pre | 跳過元素和它的子元素編譯過程 |
v-once | 只渲染元素和組件一次 |
v-memo (3.2+) | 緩存一個模板的子樹 |
v-cloak | 保持在元素上直到實例結束編譯 |
serverPrefetch SSR only | 組件實例在服務器上被渲染之前調用 |
:- | :- |
---|---|
<Transition> | 單個元素/組件的過渡效果 |
<TransitionGroup> | 多個元素/組件的過渡效果 |
<KeepAlive> | 緩存包裹在其中的動態切換組件 |
<Teleport> | 將其插槽內容渲染到 DOM 中的另一個位置 |
<Suspense> (Experimental) | 協調對組件樹中嵌套的異步依賴的處理 |
:- | :- |
---|---|
key | 用在 Vue 的虛擬 DOM 算法 |
ref | 元素或子組件注冊引用信息 |
is | 綁定動態組件 |
:- | :- |
---|---|
<component> | 渲染一個“元組件”用于動態組件或元素 |
<slot> | 組件模板中的插槽內容出口 |
:- | :- |
---|---|
總覽 | |
相應語言塊 | |
自動名稱推導 | |
預處理器 | |
Src 導入 | |
注釋 |
:- | :- |
---|---|
基本語法 | |
響應式 | |
使用組件 | |
使用自定義指令 | |
defineProps() 和 defineEmits() | |
defineExpose | |
useSlots() 和 useAttrs() | |
與普通的 <script> 一起使用 | |
頂層 await | |
針對 TypeScript 的功能 | |
限制 |
:- | :- |
---|---|
組件作用域 CSS | |
CSS Modules | |
CSS 中的 v-bind() |
:- | :- |
---|---|
h() | 創建虛擬 DOM 節點 |
mergeProps() | 合并多個 props 對象 |
cloneVNode() | 克隆一個 vnode |
isVNode() | 判斷一個值是否為 vnode 類型 |
resolveComponent() | 按名稱手動解析已注冊的組件 |
resolveDirective() | 按名稱手動解析已注冊的指令 |
withDirectives() | 用于給 vnode 增加自定義指令 |
withModifiers() | 用于向事件處理函數添加內置 v-on 修飾符 |
:- | :- |
---|---|
renderToString() | |
renderToNodeStream() | |
pipeToNodeWritable() | |
renderToWebStream() | |
pipeToWebWritable() | |
renderToSimpleStream() | |
useSSRContext() |
:- | :- |
---|---|
PropType<T> | 在用運行時 props 聲明時給一個 prop 標注更復雜的類型定義 |
ComponentCustomProperties | 增強組件實例類型以支持自定義全局屬性 |
ComponentCustomOptions | 擴展組件選項類型以支持自定義選項 |
ComponentCustomProps | 擴展全局可用的 TSX props |
CSSProperties | 擴展在樣式屬性綁定上允許的值的類型 |
:- | :- |
---|---|
createRenderer() | 創建一個自定義渲染器 |