【问题标题】:NuxtJs Cannot recall this.$fetch() inside methodsNuxtJs 无法在方法中调用 this.$fetch()
【发布时间】:2020-04-27 07:43:54
【问题描述】:

我的数据中有表格过滤器,我将用它来重新加载我的表格,我正在使用 this.$fetch() 来做到这一点,但碰巧我无法从我的任何方法中调用

p>
<script>
import { mapState } from 'vuex'

export default {
  async fetch({ store, error }) {
    try {
      await store.dispatch('exams/fetchExams', this.examTableFilter)
    } catch (e) {
      error({
        statusCode: 503,
        message: 'Unable to fetch exams at this time. Please try again.'
      })
    }
  },
  data() {
    return {
      examTableFilter: {
        page: 1,
        length: 10,
        search: '',
        examType: 'ism'
      },
      isModalCrewNewExamActive: false,
      isNew: 1
    }
  },
  computed: mapState({
    exams: (state) => state.exams.exams
  }),
  methods: {
    refresh() {
      this.$fetch()
    }
  }
}
</script>

【问题讨论】:

  • 有什么代码可以分享吗?
  • @MichaelGiovanniPumo 添加了代码块,谢谢。

标签: vue.js fetch nuxt.js


【解决方案1】:

我遇到了这个问题,我找到了答案。

问题是在您的 fetch 声明中添加参数会破坏它 (fetch({ store, error }))。根据文档,它们不应该在那里,您应该从 this.$nuxt.context 中拉出它们:

const { store, error } = this.$nuxt.context

进行这些更改,您会发现这一切都神奇地发挥作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-02
    • 2020-10-09
    • 1970-01-01
    • 2021-03-04
    • 2013-02-16
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    相关资源
    最近更新 更多