Meituan-Dianping/mpvue · error

v-once can only be used inside v-for that is keyed.

Error message

v-once can only be used inside v-for that is keyed. 

What it means

Dev-only codegen warning from genOnce: an element marked v-once sits inside a v-for whose ancestor chain has no key. Static-once nodes inside a keyed diff require the enclosing v-for key to track identity; without it the _o() cache marker cannot be generated correctly, so the compiler warns and falls back to normal element generation.

Source

Thrown at packages/weex-template-compiler/build.js:2816

}

// v-once
function genOnce (el, state) {
  el.onceProcessed = true;
  if (el.if && !el.ifProcessed) {
    return genIf(el, state)
  } else if (el.staticInFor) {
    var key = '';
    var parent = el.parent;
    while (parent) {
      if (parent.for) {
        key = parent.key;
        break
      }
      parent = parent.parent;
    }
    if (!key) {
      process.env.NODE_ENV !== 'production' && state.warn(
        "v-once can only be used inside v-for that is keyed. "
      );
      return genElement(el, state)
    }
    return ("_o(" + (genElement(el, state)) + "," + (state.onceId++) + (key ? ("," + key) : "") + ")")
  } else {
    return genStatic(el, state)
  }
}

function genIf (
  el,
  state,
  altGen,
  altEmpty
) {
  el.ifProcessed = true; // avoid recursion
  return genIfConditions(el.ifConditions.slice(), state, altGen, altEmpty)

View on GitHub (pinned to 6c5d78ee04)

Solutions

  1. Add a unique :key to the v-for that contains the v-once element
  2. Remove v-once if the node must update per render
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/weex-template-compiler/build.js:2816 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/fed86e16843ddc9c. Report an issue: GitHub.