{"record":{"id":"6bb0ac636d5b8dd6","repo":"Meituan-Dianping/mpvue","slug":"method-key-has-already-been-defined-as-a-data","errorCode":null,"errorMessage":"method \"${key}\" has already been defined as a data property.","messagePattern":"method \"(.+?)\" has already been defined as a data property\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/weex-vue-framework/factory.js","lineNumber":3148,"sourceCode":"    : data || {};\n  if (!isPlainObject(data)) {\n    data = {};\n    process.env.NODE_ENV !== 'production' && warn(\n      'data functions should return an object:\\n' +\n      'https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function',\n      vm\n    );\n  }\n  // proxy data on instance\n  var keys = Object.keys(data);\n  var props = vm.$options.props;\n  var methods = vm.$options.methods;\n  var i = keys.length;\n  while (i--) {\n    var key = keys[i];\n    if (process.env.NODE_ENV !== 'production') {\n      if (methods && hasOwn(methods, key)) {\n        warn(\n          (\"method \\\"\" + key + \"\\\" has already been defined as a data property.\"),\n          vm\n        );\n      }\n    }\n    if (props && hasOwn(props, key)) {\n      process.env.NODE_ENV !== 'production' && warn(\n        \"The data property \\\"\" + key + \"\\\" is already declared as a prop. \" +\n        \"Use prop default value instead.\",\n        vm\n      );\n    } else if (!isReserved(key)) {\n      proxy(vm, \"_data\", key);\n    }\n  }\n  // observe data\n  observe(data, true /* asRootData */);\n}","sourceCodeStart":3130,"sourceCodeEnd":3166,"githubUrl":"https://github.com/Meituan-Dianping/mpvue/blob/6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b/packages/weex-vue-framework/factory.js#L3130-L3166","documentation":"Vue iterates data keys and warns if a key collides with an existing method name. The method and reactive data property would fight over the same instance property, so Vue flags the ambiguity; the data proxy still wins on the instance.","triggerScenarios":"A component defines methods.foo and data() { return { foo: ... } } at the same time — checkKeys is populated with data keys and hasOwn(methods, key) matches.","commonSituations":"Refactoring data into methods (or vice versa) and leaving the old declaration, mixin merge introducing a method that shares a name with a data key, or inheritance of a base component's methods.","solutions":["Rename the data property or the method so names are unique","Check merged mixins/extends for name collisions","If the value should be stateful, delete the methods entry; if derived, use computed instead of data"],"exampleFix":"// before\nmethods: { load() {} },\ndata() { return { load: true }; }\n// after\nmethods: { load() {} },\ndata() { return { isLoading: true }; }","handlingStrategy":"validation","validationCode":"function checkDataMethodCollisions(options) {\n  const methods = options.methods || {};\n  const dataKeys = Object.keys(typeof options.data === 'function' ? options.data() : (options.data || {}));\n  return dataKeys.filter(k => k in methods);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep data keys and method names in disjoint namespaces (e.g. is* for state, verbs for methods)","Audit mixins for name overlaps","Use a lint rule to flag duplicate option keys"],"tags":["vue","naming-collision","data","methods"],"backgroundTag":"option-name-collision","analyzedSha":"6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b","analyzedAt":"2026-09-02T05:17:40.946Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}