NO.1 vue中的计算属性computed是不能传参的,只能通过变通的方法
比如:{{getUserNames(userInfo)}}
这里面的数据userInfo里包含许多user的信息,信息里有姓名、年龄、职位等,这里获取所有用户的姓名信息
那在js部分:
computed(){
getUserNames: function(userInfo){
return function(userInfo){
return userInfo.map((item)=>{
item.name;
})
};
}
}
另一种情况的思路:
computed: {
goodsType: function(type){
switch(type) {
case3:
return"color: #ff9900"
break;
case5:
return"color: #00BC0C"
break;
}
}
}
网友评论