Reputation: 21
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.
Upvotes: 2
Views: 16059
Reputation: 6077
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.
Upvotes: 1
Reputation: 31352
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
Upvotes: 3
Reputation: 829
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.
Upvotes: 3