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

Each computed property must be a function (getter) or an object with at least a get function. If computed[key] is an object without a getter, Vue warns and substitutes noop so the property evaluates to undefined instead of crashing.

Source

Thrown at packages/weex-vue-framework/factory.js:3188

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

var computedWatcherOptions = { lazy: true };

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

  for (var key in computed) {
    var userDef = computed[key];
    var 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. Add a get function to the computed object
  2. Convert the property to a plain function if only reading is needed
  3. Remove the computed entry if it is intentionally write-only and use a method or watcher instead
  4. Check for typo'd keys (get vs getter) in the options object

Example fix

// before
computed: {
  fullName: {
    set(v) { this.name = v; }
  }
}
// after
computed: {
  fullName: {
    get() { return this.first + ' ' + this.last; },
    set(v) { this.name = v; }
  }
}
Defensive patterns

Strategy: validation

Validate before calling

function validateComputedGetters(options) {
  return Object.entries(options.computed || {})
    .filter(([, def]) => typeof def === 'object' && typeof def.get !== 'function' && typeof def !== 'function')
    .map(([key]) => key);
}

Type guard

function hasComputedGetter(def) {
  return typeof def === 'function' || (def && typeof def.get === 'function');
}

Prevention

When it happens

Trigger: Declaring computed: { foo: { set(v) {...} } } with no get, or computed: { foo: {} } / computed: { foo: undefined } in the component definition.

Common situations: Copy-pasting a write-only computed with a setter and deleting the getter, typos like get() vs getter, or dynamically built options objects where the getter is conditionally omitted.

Related errors


AI-assisted analysis of Meituan-Dianping/mpvue@6c5d78ee04 (2026-09-02). Data as JSON: /api/errors/9659a4bca4da6385. Report an issue: GitHub.