if语句
jumpDetails(item) {
if (item.lightStatus === 'red') {
this.nowA1.status = 2
}
if (item.lightStatus === 'yellow') {
this.nowA1.status = 3
}
if (item.lightStatus === 'green') {
this.nowA1.status = 1
}
this.nowA1.display = 'one'
this.close = true
this.dialogVisible = true
}
开关语句
jumpDetails(item) {
switch (item.lightStatus) {
case 'red':
this.nowA1.status = 2
break
case 'yellow':
this.nowA1.status = 3
break
case 'green':
this.nowA1.status = 1
break
default:
return
}
this.nowA1.display = 'one'
this.close = true
this.dialogVisible = true
}
对象方法(策略模式)
jumpDetails(item) {
const value = item.lightStatus
console.log(item)
const obj = {
'red': 2,
'yellow': 3,
'green': 1
}
this.nowA1.status = obj[value] ? obj[value] : ''
this.nowA1.display = 'one'
this.close = true
this.dialogVisible = true
}
```