合並多個道具對象,對某些道具進行特殊處理。
類型
function mergeProps(...args: object[]): object
細節
mergeProps()
支持合並多個道具對象,並對以下道具進行特殊處理:
class
style
onXxx
事件偵聽器 - 多個具有相同名稱的偵聽器將合並到一個數組中。
如果您不需要合並行為並且想要簡單的覆蓋,則可以使用原生對象擴展。
示例
import { mergeProps } from 'vue'
const one = {
class: 'foo',
onClick: handlerA
}
const two = {
class: { bar: true },
onClick: handlerB
}
const merged = mergeProps(one, two)
/**
{
class: 'foo bar',
onClick: [handlerA, handlerB]
}
*/
相關用法
- Vue.js methods用法及代碼示例
- Vue.js mixins用法及代碼示例
- Vue.js markRaw()用法及代碼示例
- Vue.js useSSRContext()用法及代碼示例
- Vue.js app.directive()用法及代碼示例
- Vue.js app.config.warnHandler用法及代碼示例
- Vue.js pipeToWebWritable()用法及代碼示例
- Vue.js app.use()用法及代碼示例
- Vue.js v-pre用法及代碼示例
- Vue.js h()用法及代碼示例
- Vue.js serverPrefetch用法及代碼示例
- Vue.js customRef()用法及代碼示例
- Vue.js <Transition>用法及代碼示例
- Vue.js inject()用法及代碼示例
- Vue.js ComponentCustomProps用法及代碼示例
- Vue.js reactive()用法及代碼示例
- Vue.js ComponentCustomProperties用法及代碼示例
- Vue.js app.mount()用法及代碼示例
- Vue.js <component>用法及代碼示例
- Vue.js createRenderer()用法及代碼示例
- Vue.js onMounted()用法及代碼示例
- Vue.js createApp()用法及代碼示例
- Vue.js app.config.errorHandler用法及代碼示例
- Vue.js v-on用法及代碼示例
- Vue.js components用法及代碼示例
注:本文由純淨天空篩選整理自vuejs.org大神的英文原創作品 mergeProps()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。