2

I am using "if" and "else-if" but is giving me compilation error.

[Vue warn]: Failed to resolve directive: else-if

this is my code

var app = new Vue({
  el:"#app",
  data:{
      lab_status : 2
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.28/vue.js"></script>
<div id="app">
  <span v-if="lab_status==0">Inactive</span>
  <span v-else-if="lab_status==1">Active</span>
  <span v-else>Expired</span>
</div>

Please help me to resove this.

devendra
  • 21
  • 1
  • 1
  • 3

3 Answers3

3

v-else-if is added in vue 2.1.0 but you are using version 1.0.28, that's why the error, update the vue version or use v-if only

<span v-if="lab_status==0">Inactive</span> 
<span v-if="lab_status==1">Active</span> 
<span v-if="lab_status!=1 && lab_status!=0">Expired</span>

See v-else-if

tony19
  • 125,647
  • 18
  • 229
  • 307
Vamsi Krishna
  • 30,568
  • 8
  • 70
  • 78
3

I think you have some wrong use of v-if and v-else.

Please check if you have a tag with v-if and v-else at the same time.

<span v-else v-if="lab_status==1">Inactive</span>

You can use v-else-if instead.

First Arachne
  • 786
  • 1
  • 8
  • 18
1

From this document v-else-if directive

New in 2.1.0

So update your vuejs version

For now you can use only v-if and v-else

<span v-if="lab_status==0">Inactive</span>
<span v-if="lab_status==1">Active</span>
<span v-if="lab_status!=0&&lab_status!=1">Expired</span>

Note: In your case you have to use v-if only. If you use v-else, then for lab_status=0 both Inactive and Expired will display.

tony19
  • 125,647
  • 18
  • 229
  • 307
Emdadul Sawon
  • 5,730
  • 3
  • 45
  • 48