[Vuejs]-Check if json array is empty at store vuex

3👍

Check its length property.

<div v-if="this.$store.getters.getDocument.length != 0">
    <button class="btn btn-success btn-block">Create Document</button>
</div>

Or assign the vuex variable to null when there are no elements. Than this should work.

<div v-if="this.$store.getters.getDocument">
    <button class="btn btn-success btn-block">Create Document</button>
</div>

1👍

In your store did u define the getter “getDocument”, if so add a computed property in your component, it much cleaner and more reusable then referencing the store getters in the template directly:

computed : {
   document: function() { 
       return this.$store.getters.getDocument; 
   }
}

in the template:

<div v-if="document.length">
    <button class="btn btn-success btn-block">Create Document</button>
</div>

Leave a comment