sendGiveWeb: {
code: 200,
success: true,
data: [
{ id: "1230", name: "lh" },
{ id: "1331", name: "lh" },
{ id: "1233", name: "lh" },
],
length: 0
}
mounted() {
this.tholy();
},
methods: {
tholy() {
//data和this.sendGiveWeb.length必须是值而且是为true的
//为啥这里要写短路运算符 因为有些时候需要两个同时存在
if (this.sendGiveWeb.data && this.sendGiveWeb.length) {
alert(1);
}
}
}
有些时候 真的有必要将短路运算符 添加到判断条件中去 这样可以提高代码的健壮性哈。