{"record":{"id":"01769e31132dcc59","repo":"Meituan-Dianping/mpvue","slug":"method-key-has-an-undefined-value-in-the-comp-01769e","errorCode":null,"errorMessage":"method \"${key}\" has an undefined value in the component definition. Did you reference the function correctly?","messagePattern":"method \"(.+?)\" has an undefined value in the component definition\\. Did you reference the function correctly\\?","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/core/instance/state.js","lineNumber":242,"sourceCode":"      if (watcher.dirty) {\n        watcher.evaluate()\n      }\n      if (Dep.target) {\n        watcher.depend()\n      }\n      return watcher.value\n    }\n  }\n}\n\nfunction initMethods (vm: Component, methods: Object) {\n  process.env.NODE_ENV !== 'production' && checkOptionType(vm, 'methods')\n  const props = vm.$options.props\n  for (const key in methods) {\n    vm[key] = methods[key] == null ? noop : bind(methods[key], vm)\n    if (process.env.NODE_ENV !== 'production') {\n      if (methods[key] == null) {\n        warn(\n          `method \"${key}\" has an undefined value in the component definition. ` +\n          `Did you reference the function correctly?`,\n          vm\n        )\n      }\n      if (props && hasOwn(props, key)) {\n        warn(\n          `method \"${key}\" has already been defined as a prop.`,\n          vm\n        )\n      }\n    }\n  }\n}\n\nfunction initWatch (vm: Component, watch: Object) {\n  process.env.NODE_ENV !== 'production' && checkOptionType(vm, 'watch')\n  for (const key in watch) {","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/Meituan-Dianping/mpvue/blob/6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b/src/core/instance/state.js#L224-L260","documentation":"Vue dev-mode warning from initMethods when a method's value is undefined or null in the component definition. Vue binds it to a noop so calls do not crash, but the handler does nothing. This usually means a broken import or a typo in the methods object.","triggerScenarios":"methods:{ handleClick } where handleClick is not imported/defined; circular-import yielding undefined at definition time; assigning a variable that is declared but not yet initialized (e.g. const defined below in module scope); accidental comma leaving a key with no value after destructuring.","commonSituations":"Refactors removing a function but leaving the methods entry; bad barrel-file imports; tree-shaking or bundler misconfiguration dropping the export; typo'd function name in an import list.","solutions":["Check the import statement for the method and fix the source of undefined","Verify the exported name matches (named vs default export)","Log the methods object at module scope to see which value is undefined","If intentionally optional, provide a real fallback function instead of null"],"exampleFix":"// before\nimport { submtForm } from './api'\nexport default { methods: { submitForm: submtForm } }\n// after\nimport { submitForm } from './api'\nexport default { methods: { submitForm } }","handlingStrategy":"validation","validationCode":"function findUndefinedMethods(methods) {\n  return Object.keys(methods || {}).filter(k => methods[k] == null)\n}\n// call before creating the component options object","typeGuard":"function allMethodsDefined(methods) { return Object.values(methods || {}).every(fn => typeof fn === 'function') }","tryCatchPattern":null,"preventionTips":["Use ES module imports so missing exports fail at build time","Enable no-undef / import linting","Avoid re-exporting methods through barrels without testing the export"],"tags":["vue","methods","undefined-value","broken-import"],"backgroundTag":"undefined-handler-reference","analyzedSha":"6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b","analyzedAt":"2026-09-02T05:17:40.946Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}