Meituan-Dianping/mpvue · error
data functions should return an object: https://vuejs.org/v2
Error message
data functions should return an object: https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function
What it means
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.
Source
Thrown at src/core/instance/state.js:123
}
// static props are already proxied on the component's prototype
// during Vue.extend(). We only need to proxy props defined at
// instantiation here.
if (!(key in vm)) {
proxy(vm, `_props`, key)
}
}
observerState.shouldConvert = true
}
function initData (vm: Component) {
let data = vm.$options.data
data = vm._data = typeof data === 'function'
? getData(data, vm)
: data || {}
if (!isPlainObject(data)) {
data = {}
process.env.NODE_ENV !== 'production' && warn(
'data functions should return an object:\n' +
'https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function',
vm
)
}
// proxy data on instance
const keys = Object.keys(data)
const props = vm.$options.props
const methods = vm.$options.methods
let i = keys.length
while (i--) {
const key = keys[i]
if (process.env.NODE_ENV !== 'production') {
if (methods && hasOwn(methods, key)) {
warn(
`method "${key}" has already been defined as a data property.`,
vm
)View on GitHub (pinned to 6c5d78ee04)
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)
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at src/core/instance/state.js:123 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Meituan-Dianping/mpvue@6c5d78ee04 (2026-09-02).
Data as JSON: /api/errors/904f23202213efb3.
Report an issue: GitHub.