一般情况下,对现有data中的数据做设计
computed:{//计算属性:methods,computed重名时只会执行methods方法
currentTime2:function(){
return Date.now();
},
fullName:{
get(){
return this.firstName + "-" + this.lastName;
},
set(value){
let arr=value.split('-');//以-为基准划分字符串并加入数组
this.firstName=arr[0];
this.lastName=arr[1];
}
}
//简写:在只考虑读取,不考虑修改的情况下才能使用简写
/*
fullName(){
return this.firstName + "-" + this.lastName;
}
*/
}
带参数使用,例如在数据列表中把文件后缀提出来、根据不同状态返回不同颜色展示
<div class="BorrowRightInitiate">
<div class="status" :style="{ color: colorValue(borrow.status) }">
{{ borrow.status }}
</div>
</div>
computed: {
colorValue() {
return function (val) {
if (val == "审批通过/借阅中") {
return "#886DEC";
} else if (val == "审批拒绝") {
return "#DE5353";
} else {
return "#5C5C5C";
}
};
},
},