如果您想从 Vue 表格中删除时间,您可以使用 moment.js 库来格式化时间。以下是一个示例代码,演示如何在 Vue 表格中删除时间:

<template>
  <div>
    <table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Date</th>
          <th>Actions</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(item, index) in items" :key="index">
          <td>{{ item.name }}</td>
          <td>{{ formatDate(item.date) }}</td>
          <td><button @click="deleteItem(index)">Delete</button></td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
import moment from 'moment';

export default {
  data() {
    return {
      items: [
        { name: 'Item 1', date: '2021-10-01T10:30:00.000Z' },
        { name: 'Item 2', date: '2021-10-05T14:45:00.000Z' },
        { name: 'Item 3', date: '2021-10-08T08:15:00.000Z' }
      ]
    }
  },
  methods: {
    formatDate(date) {
      return moment(date).format('YYYY-MM-DD');
    },
    deleteItem(index) {
      this.items.splice(index, 1);
    }
  }
}
</script>

在上面的示例中,我们使用 moment.js 来格式化日期并删除时间。在 formatDate 方法中,我们将传入的日期字符串转换为 Moment 对象,然后使用 format() 方法将其格式化为所需的日期格式。这样,我们可以在表格中显示日期而不是时间

vue表格如何删除时间

原文地址: http://www.cveoy.top/t/topic/eRos 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录