如果一个对象里有值就返回该值,否则返回空字符串
computed: {
currentMsg () {
const current = this.list[this.current] || {}
return {
name: current.name || '',
age: current.age || '',
gender: current.gender || ''
}
}
}
【拓展】
[]||1 // []
({})||1 // {}