vue3-core/packages/runtime-core/src/helpers/toHandlers.ts

19 lines
468 B
TypeScript

import { isObject, capitalize } from '@vue/shared'
import { warn } from '../warning'
/**
* For prefixing keys in v-on="obj" with "on"
* @private
*/
export function toHandlers(obj: Record<string, any>): Record<string, any> {
const ret: Record<string, any> = {}
if (__DEV__ && !isObject(obj)) {
warn(`v-on with no argument expects an object value.`)
return ret
}
for (const key in obj) {
ret[`on${capitalize(key)}`] = obj[key]
}
return ret
}