{"record":{"id":"2a8d3536f749a7fb","repo":"Meituan-Dianping/mpvue","slug":"v-el-elseif-else-if-el-elseif","errorCode":null,"errorMessage":"v-${el.elseif ? ('else-if=\"' + el.elseif + '\"') : 'else'} used on element <${el.tag}> without corresponding v-if.","messagePattern":"v-(.+?) used on element <(.+?)> without corresponding v-if\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/weex-template-compiler/build.js","lineNumber":1694,"sourceCode":"    if (getAndRemoveAttr(el, 'v-else') != null) {\n      el.else = true;\n    }\n    var elseif = getAndRemoveAttr(el, 'v-else-if');\n    if (elseif) {\n      el.elseif = elseif;\n    }\n  }\n}\n\nfunction processIfConditions (el, parent) {\n  var prev = findPrevElement(parent.children);\n  if (prev && prev.if) {\n    addIfCondition(prev, {\n      exp: el.elseif,\n      block: el\n    });\n  } else if (process.env.NODE_ENV !== 'production') {\n    warn(\n      \"v-\" + (el.elseif ? ('else-if=\"' + el.elseif + '\"') : 'else') + \" \" +\n      \"used on element <\" + (el.tag) + \"> without corresponding v-if.\"\n    );\n  }\n}\n\nfunction findPrevElement (children) {\n  var i = children.length;\n  while (i--) {\n    if (children[i].type === 1) {\n      return children[i]\n    } else {\n      if (process.env.NODE_ENV !== 'production' && children[i].text !== ' ') {\n        warn(\n          \"text \\\"\" + (children[i].text.trim()) + \"\\\" between v-if and v-else(-if) \" +\n          \"will be ignored.\"\n        );\n      }","sourceCodeStart":1676,"sourceCodeEnd":1712,"githubUrl":"https://github.com/Meituan-Dianping/mpvue/blob/6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b/packages/weex-template-compiler/build.js#L1676-L1712","documentation":"v-else or v-else-if was used on an element whose previous sibling does not carry v-if (or is absent entirely). Without an adjacent v-if, the conditional directive has nothing to attach to, so the compiler warns and the element is treated as unconditional.","triggerScenarios":"Writing v-else / v-else-if on an element where processIfConditions finds either no previous sibling (prev is falsy) or prev has no .if property — e.g. an intervening element, a text/comment node breaking adjacency, or v-if on a non-sibling.","commonSituations":"Placing a whitespace-producing element or another tag between the v-if element and the v-else, putting v-else on the same element as v-if, or reordering elements so the v-if block no longer immediately precedes the else block.","solutions":["Ensure the v-else/v-else-if element is the immediately following sibling of an element with v-if","Remove any elements between the v-if and v-else elements","Move v-else off elements that already have v-if"],"exampleFix":"// before\n<div v-if=\"ok\">A</div>\n<span>other</span>\n<div v-else>B</div>\n// after\n<div v-if=\"ok\">A</div>\n<div v-else>B</div>","handlingStrategy":"validation","validationCode":"function checkElseAdjacency(template) {\n  // element with v-else must be immediately preceded by an element with v-if/v-else-if\n  const re = /<(?!template)([\\w-]+)([^>]*)>/g;\n  let m, prev = null;\n  while ((m = re.exec(template))) {\n    const attrs = m[2];\n    if (/\\sv-else(-if)?[=\\s>]/.test(attrs) && !(prev && /\\sv-(if|else-if)[=\\s]/.test(prev))) {\n      return `v-else on <${m[1]}> without preceding v-if`;\n    }\n    prev = attrs;\n  }\n  return null;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep v-if and v-else/v-else-if elements as immediate siblings","Never place elements between v-if and v-else blocks","Don't put v-else on an element that already has v-if"],"tags":["v-if","v-else","template","vue","weex"],"backgroundTag":"else-without-if","analyzedSha":"6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b","analyzedAt":"2026-09-02T05:17:40.946Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}