VUE 模板 v-if 判断 数组是否为空

Posted 猎人在吃肉

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VUE 模板 v-if 判断 数组是否为空相关的知识,希望对你有一定的参考价值。

vue 模板 v-if 判断数组是否为空 :

为空:array == undefined ||array == null || array.length <= 0     (顺序不能调换)

不为空: array !==undefined && array != null  && array.length > 0   (顺序不能调换)

示例:

<ul v-if="commentList == undefined ||commentList == null || commentList.length <= 0 " >
	暂无评论!
</ul>

<ul v-if="commentList != undefined && commentList != null && commentList.length > 0 " >
	<li class="list-group-item"  v-for="(item,index) in commentList"  >
		<div class="username">
			 item.username  说:
		</div>
		<div class="content" >
			 item.content 
		</div>
	</li>
</ul>

以上是关于VUE 模板 v-if 判断 数组是否为空的主要内容,如果未能解决你的问题,请参考以下文章

vue.js的v-if判断数组多少个

vue中使用v-if判断数组长度是出现length报错

Vue v-if 语句检查变量是不是为空或 null

vue中当数据为空时的处理

11 v-if 更好颜色三元运算符

js判断一个对象是否为空对象