<template>
  <span>{{ showText }}</span>
</template>

<script>
import dateFormat from "dai-js/tools/dateFormat";

export default {
  name: "dateShow",
  props: {
    format: {
      type: String,
      default: "yyyy-MM-dd hh:mm:ss",
    },
    timestamp: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      showText: "",
    };
  },
  computed: {},
  watch: {
    timestamp(val) {
      this.computeShowText();
    },
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      this.computeShowText();
    },

    computeShowText() {
      const { timestamp, format } = this;
      if (!timestamp) return;
      const showText = dateFormat(new Date(timestamp * 1000), format);

      this.showText = showText;
    },
  },
};
</script>
