admin管理员组文章数量:1318772
I have a for-loop running in vue using v-for that loops through a media object to see if there are images stored. That works correctly, but now I want a div displayed below it saying "There is no media" if the object is empty. The text "There is no media" always displays though. Any help on this would be greatly appreciated.
Below is my code:
<v-flex>
<p><v-flex sm3 v-for="media in current_sample.media" :key="media.id">
<v-btn @click="delete_image(media.id)">[X]</v-btn> <img :src="'/' + media.path" class="rotateImg" />
</v-flex>
<v-flex sm3 v-if="current_sample.media">There is no media</v-flex>
</p>
</v-flex>
I have a for-loop running in vue using v-for that loops through a media object to see if there are images stored. That works correctly, but now I want a div displayed below it saying "There is no media" if the object is empty. The text "There is no media" always displays though. Any help on this would be greatly appreciated.
Below is my code:
<v-flex>
<p><v-flex sm3 v-for="media in current_sample.media" :key="media.id">
<v-btn @click="delete_image(media.id)">[X]</v-btn> <img :src="'https://orderinformation.s3.amazonaws./' + media.path" class="rotateImg" />
</v-flex>
<v-flex sm3 v-if="current_sample.media">There is no media</v-flex>
</p>
</v-flex>
Share
Improve this question
asked Oct 2, 2019 at 15:16
SJW525SJW525
512 silver badges11 bronze badges
2
-
Test specific property instead of object, like
v-if="current_sample.media.path !== '' "
– DedaDev Commented Oct 2, 2019 at 15:21 - @Deda I did it now says this error: "Cannot read property 'path' of undefined" in console – SJW525 Commented Oct 2, 2019 at 15:31
2 Answers
Reset to default 4You can use Object.entries property :
<v-flex sm3 v-if="!Object.entries(current_sample.media).length">There is no media</v-flex>
You can use Object.keys which is patible with all browsers
v-if="Object.keys(obj).length"
本文标签: javascriptHow to check if a vue object is empty in vue using vifStack Overflow
版权声明:本文标题:javascript - How to check if a vue object is empty in .vue using v-if - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742047267a2417862.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论