html代码
 <div class="item-right">
                  {{ date | formaDate }}
                </div>
js 代码 
<script>
var padaDate = function(value) {
  return value < 10 ? "0" + value : value;
};
export default {
  data() {
    return {
      code: "",
      report_info: {},
      date: new Date()
    };
  },
  created() {},
  filters: {
    //设置一个函数来进行过滤
    formaDate: function(value) {
      //创建一个时间日期对象
      var date = new Date();
      var year = date.getFullYear(); //存储年
      var month = padaDate(date.getMonth() + 1); //存储月份
      var day = padaDate(date.getDate()); //存储日期
      var hours = padaDate(date.getHours()); //存储时
      var minutes = padaDate(date.getMinutes()); //存储分
      var seconds = padaDate(date.getSeconds()); //存储秒
      //返回格式化后的日期
      return (
        year +
        "-" +
        month +
        "-" +
        day +
        " " +
        hours +
        ":" +
        minutes +
        ":" +
        seconds 
      );
    }
  },
  mounted() {
    this.view();
    //创建定时器更新时间
    var _this = this;
    this.timeId = setInterval(function() {
      _this.date = new Date();
    }, 1000);
  },
  beforeDestroy: function() {
    //实例销毁前青出于定时器
    if (this.timeId) {
      clearInterval(this.timeId);
    }
  },
 
Logo

前往低代码交流专区

更多推荐