我遇到了以下问题,希望有人可以帮助我:
首次加载(也不重新加载)时,Fetch 不起作用。它仅在客户端时有效(当我在路线之间移动时)。
我读到 watchQuery 可以提供帮助,但不明白为什么以及如何使用它。
<script>
export default {
async fetch() {
const userId = await this.$nuxt.context.store.state.auth.authUser.userId
await this.$store.dispatch('case/fetchMyCases', userId.uid)
await this.$store.dispatch('case/fetchMyPendingCases', userId.uid)
...
直接导入使用firebase/auth也不起作用。
<script>
import * as firebase from 'firebase/app'
import 'firebase/auth'
export default {
async fetch() {
const userId = await firebase.auth().currentUser
await this.$store.dispatch('case/fetchMyCases', userId.uid)
await this.$store.dispatch('case/fetchMyPendingCases', userId.uid)
...
有人有任何建议吗?我真的很感激。
谢谢!
最佳答案
经过三天的搜索/测试,我终于找到了为什么会出现这个问题。
问题是我只是将 async/await 用于获取,但没有将 async/await 用于操作本身。因此,我的 getter(计算的)在调度完成之前获取存储状态。
谢谢大家!
关于vue.js - Nuxt Fetch 在首次加载时不会更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61152269/