0

我使用 vuetifyv-data-table和服务器端 & 分页 + SSR 进行了粗鲁的操作。问题是页面加载后正在获取数据。有什么方法可以在页面加载之前加载数据,与 SSRasyncData或 fetch 挂钩?

零件:

<v-data-table
      :headers="headers"
      :items="list"
      item-key="_id"
      :options.sync="options"
      :server-items-length="countItems"
      :items-per-page="10"
      :footer-props="{
          itemsPerPageOptions:[10,50,100,-1],
          'show-current-page': true,
          'show-first-last-page': true
      }"
      dense
    />

手表:

watch:{    
    params: {
      handler() {
        this.filteredCustomers();
      },
      deep: true
    }
  }
methods: {
    async filteredCustomers(){
      try {
        const { data } = await this.$axios.post(`${process.env.CUSTOMER_SERVICE}/fetch-filtered-customers`, this.params );
        this.countItems = data.count[0]?.__v || 0
        this.list = data.customers;
      } catch (error) {
        this.$notifier.showMessage( { message : error.response?.data || error } );
      }
    },
}

computed: {

    params(nv) {
      return {
        ...this.options,
        search: this.search,
        type: this.filter
      }
    }
}
4

0 回答 0