一般情况下,对现有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";
        }
      };
    },
  },

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐