Meituan-Dianping/mpvue · error

method "${key}" has already been defined as a data property.

Error message

method "${key}" has already been defined as a data property.

What it means

Fires inside the initData proxying loop when a key in data collides with a key already defined in the options.methods object. Both data properties and methods are proxied directly onto the vm instance, so a shared name means whichever is defined later would overwrite the earlier binding; Vue warns (in dev) and the data property takes the instance slot, shadowing the method. The method itself still exists in vm.$options.methods.

Source

Thrown at src/core/instance/state.js:138

    : 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
        )
      }
    }
    if (props && hasOwn(props, key)) {
      process.env.NODE_ENV !== 'production' && warn(
        `The data property "${key}" is already declared as a prop. ` +
        `Use prop default value instead.`,
        vm
      )
    } else if (!isReserved(key)) {
      proxy(vm, `_data`, key)
    }
  }
  // observe data
  observe(data, true /* asRootData */)
}

View on GitHub (pinned to 6c5d78ee04)

Solutions

  1. Rename either the data property or the method so they no longer share a key
  2. If a value and an action belong together, keep the value in data and give the method a distinct verb-style name (e.g. value 'count', method 'incrementCount')
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/core/instance/state.js:138 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/3de4b929513d168e. Report an issue: GitHub.