New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: v-empty #2764
Comments
While I'm a fan of little utilities like this, a client-side JavaScipt library shouldn't cover them due to size and performance issues. Server-side frameworks like Laravel and Django, on the other hand, have all my support. |
@asmaps You could also simply use <div v-for="(index, item) in items">
{{ index }} {{ item.message }}
</div>
<div v-if="items.length == 0">
<p>Sorry, no elements yet.</p>
</div> If you needed to handle both Arrays and Objects, a basic method implementation could be: {
isEmpty (value) {
if (!!value && value instanceof Array) {
return value.length < 1
}
if (!!value && typeof value === 'object') {
for (var key in value) {
if (hasOwnProperty.call(value, key)) {
return false
}
}
}
return !value // Fallback for strings, etc.
}
} |
@taylorzane sure I can use |
Exactly. And that's why we had internal discussions about |
@phanan - do you mean the overall size of the library or do you mean rendering performance? This doesn't seem like it would be any more intensive than a v-if/v-else or v-if/v-for. Also, maybe this could be implemented as a plugin? |
I meant both, regarding those small utilities. |
As stated in #677 currently you have to wrap a v-for with an if to catch if an array is empty. I'd love a tag like
v-empty
to do that. It would work likev-else
and you put it right after av-for
(maybe alsov-else
could also be reused for that?).The
v-empty
block triggeres if thev-for
list is empty. Just like the equivalent django template tag: https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#for-emptyExample:
The text was updated successfully, but these errors were encountered: