需求: 在返回的数据中,时间日期为2012-12-12 12:12:12
但是只需要2012-12-12,想到使用计算属性
找了一圈还是没找到怎么使用.于是参考vue官网可以使用方法return返回的形式

 // 数据格式:
   myNoticeList=[{last:2012-12-12 00:00:00}]
// html
<li  v-for="(item,index) in myNoticeList" :key="index">
          <span >{{last(item.last)}}</span>
</li>
methods: {
    last(val) {
     console.log(val) // 2012-12-12 00:00:00
      let time = val;
      let timearr = time.replace(" ", ":").replace(/\:/g, "-").split("-");//["2012", "12", "12", "00", "00", "00"]
      let timestr = timearr[0] + "-" + timearr[1] + "-" + timearr[2];// 2012-12-12
      return timestr;
    },
 }

但是在想还有没有另一种方式,如果有的话麻烦大佬告知.谢谢

Logo

前往低代码交流专区

更多推荐