如何使用 Nuxt Auth 模块在 Vuex 中重新获取用户? [英] How to refetch user in Vuex with Nuxt Auth Module?

查看:74
本文介绍了如何使用 Nuxt Auth 模块在 Vuex 中重新获取用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

小问题:是否可以通过 Nuxt Auth 模块手动更新 Vuex 中的用户数据?

Short Question: Is it possible to update the user data in Vuex manually via the Nuxt Auth Module?

为什么我会有这个问题:我的问题是这个.我在用户文档中的 MongoDB 中保存了一些 Likes/Follows.我的身份验证是通过 Nuxt Auth 实现的.Nuxt Auth 在登录时将我的用户文档存储在 Vuex 中.

Why do I have that Question: My problem is this. I save some Likes/Follows in MongoDB in the user document. My authentication is realized with Nuxt Auth. Nuxt Auth stores my user document in Vuex on login.

如果用户现在喜欢某样东西,它会被存储在数据库中,但我在Vuex中没有进入Nuxt Auth的auth状态.

If an user likes something now, it will be stored in the database, but I don't get it into the auth state of Nuxt Auth in Vuex.

另一种(我认为)是在 Vuex 中以与在数据库中相同的方式更改数据.但是在这里我遇到了 Vuex 的严格"模式的问题.

An alternative (I thought) would be to change the data in Vuex the same way as in the database. But here I get problems with the "Strict" mode of Vuex.

对我有用的一种可能性是在单独的状态下再保存一次用户数据,并始终手动更新它.但是我真的需要在 Vuex 中多次保存用户数据吗?对我来说没有意义.

One possibility that works for me would be to save the user data one more time in a separate state and always update it manually. But do I really have to save the user data several times in Vuex? Doesn't make sense to me.

推荐答案

现在我找到了解决方案.就这么简单:

Now I found a solution. It is as simple as:

this.$auth.fetchUser()

但我在文档中找不到它.

but I couldn't find it anywhere in the documentation.

来源:https://nuxt-auth.herokuapp.com/

这篇关于如何使用 Nuxt Auth 模块在 Vuex 中重新获取用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆