vue 判断数据是否为空
<template><div>数据是否为空</div></template><script>export default {name: "Orders",data() {return {abj: {},arr: []};},created() {//判读数组是否为空if(this.arr == undefined || this.arr.
·
vue判断对象是否为空、判断数组是否为空
<template>
<div>数据是否为空</div>
</template>
<script>
export default {
name: "Orders",
data() {
return {
abj: {},
arr: []
};
},
created() {
//判读数组是否为空
if(this.arr == undefined || this.arr.length <= 0) {
console.log("数组为空");
}
if(this.arr !== undefined && this.arr.length > 0) {
console.log("数组不为空");
}
//判断对象是否为空
if(JSON.stringify(this.obj) === "{}"){
console.log("对象为空");
} else {
console.log("对象不为空");
}
},
methods: {},
};
</script>
<style lang="scss" scoped></style>
1.数组为空
this.arr == undefined || this.arr.length <= 0
2.数组不为空
this.arr !== undefined && this.arr.length > 0
3.对象判断
JSON.stringify(this.obj) === "{}"
更多推荐
所有评论(0)