Vue: v-else attribute doesn't work

Created on 5 Jul 2016  ·  2Comments  ·  Source: vuejs/vue

Vue.js version

1.0.26

Reproduction Link

https://jsfiddle.net/koshpavel/3vh62y7r/

Steps to reproduce

All explanations are in the output

What is Expected?

Expected to not show with v-else attribute

What is actually happening?

has both v-if and v-for, both of them works fine, but next with v-else attribute still renders.

Most helpful comment

it's expected behavior.
v-for has higher priority than v-if
v-if in this case applies to each element which produces a v-for

All 2 comments

it's expected behavior.
v-for has higher priority than v-if
v-if in this case applies to each element which produces a v-for

Hi @PavelTytyuk

Adding to what @repsac-by explained, you can make it work by putting the v-if on a seperate element, like this:

    <ul v-if="contracts.length > 0">
      <li  v-for="contract in contracts">
        {{ contract }}
      </li>
    </ul>
    <div v-else>
      No contracts (now shown as expected)
    </div>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

paceband picture paceband  ·  3Comments

robertleeplummerjr picture robertleeplummerjr  ·  3Comments

franciscolourenco picture franciscolourenco  ·  3Comments

lmnsg picture lmnsg  ·  3Comments

aviggngyv picture aviggngyv  ·  3Comments