How to check if a Vuex state object is empty
I have an original empty object in Vuex state that is updated from the API.
const state = {
someObject: {}
}
How do I check if an object is empty in my template?
<template>
<div v-if="someObject">
This should not display when someObject is empty.
</div>
</template>
What's the best way to check if the state object is set / empty or not?
Should I install someObject: null/undefined/false
initially, even if it is pending update with a new object?
Does it make sense to check in getters?
export const someObject = state => Object.getOwnPropertyNames(state.someObject).length == 0 ? state.someObject : false
+3
source to share