如何在 Nuxt 中再次调用 asyncData 或 fetch 钩子?

How to call an asyncData or fetch hook again in Nuxt?

你好,我想在调用 api 时调用方法或其他解决方案中的 asyncData 函数,因为我想在调用此重置数据的操作时执行 $emit 我这样做了,但不起作用

index.vue

<template>
    <my-orders
     :orders="orders
      @sendData="initOrders"
    />
</template>
<script>
 async asyncData({ $axios }) {
    const orders = await endpoint.getOrders({ $axios });
    return {
      orders
    };
  },
 methods: {
   async initOrders() {
      await this.asyncData
    },
}
</script>

请帮忙谢谢

this.$nuxt.refresh() 可以帮助您重新获取任何 fetch()asyncData() 钩子。