如何透過查看目前日期起30天內的日期來統計物品?
P粉616383625
P粉616383625 2024-04-01 09:24:56
0
1
425

如何透過檢查目前日期起 30 天內的日期來計算我的商品數量?

以下是我需要在 30 天內為商品添加的當前代碼

<template>
  <div>
    <div>
      <div class="tree">
         <table width="100%"  border="1">
              <tr>
                <th>row</th>
                <th>Item</th>
                <th>Category</th>
                <th>Date</th>
                <th>Description</th>
              </tr>
              <tr v-for="(user,index) in bookData" v-bind:key="user.listData">
                <td>{{ user.index }}</td>
                <td>{{ user.item_id }}</td>
                <td>{{ user.category_id }}</td>
                <td>{{ user.r_date }}</td>
                <td>{{ user.description }}</td>
              </tr>
            </table>
            **New Item within 30 days :** 
        <div>
      </div>
    </div>
  </div>
</div>
</template>

<script lang="ts">
import { Vue, Watch, Component } from 'vue-property-decorator';
import API from '@/API';

@Component
export default class BookTable extends Vue {
  private bookData: any = [];
  private tempData: any = [];
  private metadata: any = JSON.stringify([], undefined, 2) ;

  private created(): void {
    this.getBookDetails();
    if (this.currentUser) {
      this.getCategories();
    }
  }

  @Watch('categories')
  private getBookDetails(): void {
    if (this.categories.length > 0) {
      for (const category of this.categories) {
        API.Book.getBook(category.id).then((response) => {
          this.bookData = this.bookData.concat(response ? response : []);
          this.tempData = this.bookData;
        });
      }
    }
  }
}
</script>

請幫忙,因為我正在嘗試了解有關 Vue 的更多信息,並且對它和打字稿還很陌生。

P粉616383625
P粉616383625

全部回覆(1)
P粉194919082

您可以為此使用計算屬性並將其連接到計算天數的函數。例如

let date_1 = new Date('10/25/2021');
let date_2 = new Date();

function numOfDaysBtn(date_1, date_2) {
    let difference = date_1.getTime() - date_2.getTime();
    let TotalDays = Math.ceil(difference / (1000 * 3600 * 24));
    return TotalDays;
}

console.log(numOfDaysBtn(date_1, date_2) + " days in between");
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!