Skip to content

Instantly share code, notes, and snippets.

@tdondich
Created May 13, 2019 03:16
Show Gist options
  • Save tdondich/80a3e0fc83cd1347049c12fabe519746 to your computer and use it in GitHub Desktop.
Save tdondich/80a3e0fc83cd1347049c12fabe519746 to your computer and use it in GitHub Desktop.
function initMethods (vm: Component, methods: Object) {
const props = vm.$options.props
for (const key in methods) {
if (process.env.NODE_ENV !== 'production') {
if (typeof methods[key] !== 'function') {
warn(
`Method "${key}" has type "${typeof methods[key]}" in the component definition. ` +
`Did you reference the function correctly?`,
vm
)
}
if (props && hasOwn(props, key)) {
warn(
`Method "${key}" has already been defined as a prop.`,
vm
)
}
if ((key in vm) && isReserved(key)) {
warn(
`Method "${key}" conflicts with an existing Vue instance method. ` +
`Avoid defining component methods that start with _ or $.`
)
}
}
vm[key] = typeof methods[key] !== 'function' ? noop : bind(methods[key], vm)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment