@@ -154,10 +154,13 @@ export function parse (
154154 root = element
155155 checkRootConstraints ( root )
156156 } else if ( ! stack . length ) {
157- // allow 2 root elements with v-if and v-else
158- if ( root . if && element . else ) {
157+ // allow root elements with v-if, v-elseif and v-else
158+ if ( root . if && ( element . elseif || element . else ) ) {
159159 checkRootConstraints ( element )
160- root . elseBlock = element
160+ addIfCondition ( root , {
161+ exp : element . elseif ,
162+ block : element
163+ } )
161164 } else if ( process . env . NODE_ENV !== 'production' && ! warned ) {
162165 warned = true
163166 warn (
@@ -166,8 +169,8 @@ export function parse (
166169 }
167170 }
168171 if ( currentParent && ! element . forbidden ) {
169- if ( element . else ) { // else block
170- processElse ( element , currentParent )
172+ if ( element . elseif || element . else ) {
173+ processIfConditions ( element , currentParent )
171174 } else if ( element . slotScope ) { // scoped slot
172175 currentParent . plain = false
173176 const name = element . slotTarget || 'default'
@@ -316,23 +319,43 @@ function processIf (el) {
316319 const exp = getAndRemoveAttr ( el , 'v-if' )
317320 if ( exp ) {
318321 el . if = exp
319- }
320- if ( getAndRemoveAttr ( el , 'v-else' ) != null ) {
321- el . else = true
322+ addIfCondition ( el , {
323+ exp : exp ,
324+ block : el
325+ } )
326+ } else {
327+ if ( getAndRemoveAttr ( el , 'v-else' ) != null ) {
328+ el . else = true
329+ }
330+ const elseif = getAndRemoveAttr ( el , 'v-elseif' )
331+ if ( elseif ) {
332+ el . elseif = elseif
333+ }
322334 }
323335}
324336
325- function processElse ( el , parent ) {
337+ function processIfConditions ( el , parent ) {
326338 const prev = findPrevElement ( parent . children )
327339 if ( prev && prev . if ) {
328- prev . elseBlock = el
340+ addIfCondition ( prev , {
341+ exp : el . elseif ,
342+ block : el
343+ } )
329344 } else if ( process . env . NODE_ENV !== 'production' ) {
330345 warn (
331- `v-else used on element <${ el . tag } > without corresponding v-if.`
346+ `v-${ el . elseif ? ( 'elseif="' + el . elseif + '"' ) : 'else' } ` +
347+ `used on element <${ el . tag } > without corresponding v-if.`
332348 )
333349 }
334350}
335351
352+ function addIfCondition ( el , condition ) {
353+ if ( ! el . conditions ) {
354+ el . conditions = [ ]
355+ }
356+ el . conditions . push ( condition )
357+ }
358+
336359function processOnce ( el ) {
337360 const once = getAndRemoveAttr ( el , 'v-once' )
338361 if ( once != null ) {
0 commit comments