开始判断是否符合条件时太low 然后去搜了一下有什么简便的方法去判断对象是否存在某个属性
if (this.showTableName === 'ldzy' ||
this.showTableName === 'gcleq' ||
this.showTableName === 'erdiao' ||
this.showTableName === 'ldbh_2011' ||
this.showTableName === 'lgsj' ||
this.showTableName === 'ldzy_2019' ||
this.showTableName === 'gsmm' ||
this.showTableName === 'tghl' ||
this.showTableName === 'smhzl_2021' ||
this.showTableName === 'dsql' ||
this.showTableName === 'shidimian' ||
this.showTableName === 'shidixian') {
console.log(this.form)
this.EchartsName = this.ChinaName[this.showTableName]
this.getEchartsData()
this.innerVisible = true
} else { // 无图表
this.$message.warning('当前数据无统计图表')
}
然后发现in是可以符合的(chinaName就是包含上述那些属性的对象)
if (this.showTableName in this.ChinaName) {
console.log(this.form)
this.EchartsName = this.ChinaName[this.showTableName]
this.getEchartsData()
this.innerVisible = true
} else { // 无图表
this.$message.warning('当前数据无统计图表')
}
下面是关于in运算符的详细介绍
1、简介:如果指定的属性在指定的对象或其原型链中,则 in
运算符返回 true
。
2、in
右操作数必须是一个对象值。例如,你可以指定使用 String
构造函数创建的字符串,但不能指定字符串文字。
3、特别是原型链上 如果一个属性是从原型链上继承的 也会返回true
"toString" in {}; // 返回true