{"record":{"id":"904f23202213efb3","repo":"Meituan-Dianping/mpvue","slug":"data-functions-should-return-an-object-https-vu-904f23","errorCode":null,"errorMessage":"data functions should return an object:\nhttps://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function","messagePattern":"data functions should return an object:\nhttps://vuejs\\.org/v2/guide/components\\.html#data-Must-Be-a-Function","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/core/instance/state.js","lineNumber":123,"sourceCode":"    }\n    // static props are already proxied on the component's prototype\n    // during Vue.extend(). We only need to proxy props defined at\n    // instantiation here.\n    if (!(key in vm)) {\n      proxy(vm, `_props`, key)\n    }\n  }\n  observerState.shouldConvert = true\n}\n\nfunction initData (vm: Component) {\n  let data = vm.$options.data\n  data = vm._data = typeof data === 'function'\n    ? getData(data, vm)\n    : 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  const keys = Object.keys(data)\n  const props = vm.$options.props\n  const methods = vm.$options.methods\n  let i = keys.length\n  while (i--) {\n    const 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        )","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/Meituan-Dianping/mpvue/blob/6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b/src/core/instance/state.js#L105-L141","documentation":"Raised in initData when the resolved data value is not a plain object: either the data option was a function whose return value was a primitive/array, getData caught an exception and returned {}, or a non-function data was set to a non-object. Vue replaces data with an empty object after warning, so the component renders with no reactive data properties — usually followed by 'Property or method is not defined' errors in the template.","triggerScenarios":"Thrown at src/core/instance/state.js:123 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Make the data option a function that returns a plain object: data() { return { count: 0 } }","Check the function's return statement — it must return an object literal, not a primitive, array, or undefined","If data() throws, fix the exception (e.g. accessing undefined nested props inside data)"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b","analyzedAt":"2026-09-02T05:17:40.946Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}