Meituan-Dianping/mpvue · error

No getter function has been defined for computed property "$

Error message

No getter function has been defined for computed property "${key}".

What it means

Emitted during initComputed for a computed entry whose definition yields no getter: the entry is neither a function (the shorthand getter form) nor an object with a .get member — e.g. computed: { foo: {} } or computed: { foo: someUndefined }. A lazy watcher is still created with an undefined getter, so evaluating the computed in a template will throw 'Cannot read properties of undefined' when the watcher's getter is invoked.

Source

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

    return data.call(vm)
  } catch (e) {
    handleError(e, vm, `data()`)
    return {}
  }
}

const computedWatcherOptions = { lazy: true }

function initComputed (vm: Component, computed: Object) {
  process.env.NODE_ENV !== 'production' && checkOptionType(vm, 'computed')
  const watchers = vm._computedWatchers = Object.create(null)

  for (const key in computed) {
    const userDef = computed[key]
    let getter = typeof userDef === 'function' ? userDef : userDef.get
    if (process.env.NODE_ENV !== 'production') {
      if (getter === undefined) {
        warn(
          `No getter function has been defined for computed property "${key}".`,
          vm
        )
        getter = noop
      }
    }
    // create internal watcher for the computed property.
    watchers[key] = new Watcher(vm, getter, noop, computedWatcherOptions)

    // component-defined computed properties are already defined on the
    // component prototype. We only need to define computed properties defined
    // at instantiation here.
    if (!(key in vm)) {
      defineComputed(vm, key, userDef)
    } else if (process.env.NODE_ENV !== 'production') {
      if (key in vm.$data) {
        warn(`The computed property "${key}" is already defined in data.`, vm)
      } else if (vm.$options.props && key in vm.$options.props) {

View on GitHub (pinned to 6c5d78ee04)

Solutions

  1. Use the function shorthand: computed: { fullName() { return this.first + ' ' + this.last } }
  2. For writable computeds, supply both members: { foo: { get() {...}, set(v) {...} } }
  3. Check that the computed value is not accidentally undefined (e.g. a bad import or a spread that dropped the function)
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at src/core/instance/state.js:178 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/17b65c08aafe3ff5. Report an issue: GitHub.