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: v-once was applied to a node inside a v-for that has no key on any ancestor v-for. The _o() once-cache marker needs the enclosing for's key to key cached static nodes; without it the compiler warns and emits the node as a normal (non-once) element.
Source
Thrown at src/compiler/codegen/index.js:111
}
// v-once
function genOnce (el: ASTElement, state: CodegenState): string {
el.onceProcessed = true
if (el.if && !el.ifProcessed) {
return genIf(el, state)
} else if (el.staticInFor) {
let key = ''
let 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)
}
}
export function genIf (
el: any,
state: CodegenState,
altGen?: Function,
altEmpty?: string
): string {
el.ifProcessed = true // avoid recursion
return genIfConditions(el.ifConditions.slice(), state, altGen, altEmpty)View on GitHub (pinned to 6c5d78ee04)
Solutions
- Add a unique :key to the v-for containing the v-once element
- Remove v-once from that node if per-item re-render is intended
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/compiler/codegen/index.js:111 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/fd0265c8ef570a45.
Report an issue: GitHub.