【发布时间】:2022-01-01 13:19:19
【问题描述】:
在这里需要一些帮助。
我希望我的导航抽屉根据登录用户的用户类型/角色显示不同的内容。
但是我遇到了这个错误(“Uncaught TypeError: Cannot set properties of undefined (setting 'isSubcon'”)。而且我的导航抽屉没有显示任何东西。
我的template
<v-list v-if="isSubcon">
//content of drawer if user that logged in is a "Subcon"
</v-list>
<v-list v-if="isWPC">
//content of drawer if user that logged in is a "WPC"
</v-list>
<v-list v-if="isBWG">
//content of drawer if user that logged in is a "BWG"
</v-list>
我的script
data: () => ({
isSubcon: false,
isWPC: false,
isBWG: false,
}),
// I think below is where the problem occurs.
created() {
firebase
.auth()
.onAuthStateChanged((userAuth) => {
if (userAuth) {
firebase
.auth()
.currentUser.getIdTokenResult()
.then(function ({
claims,
}) {
if (claims.customer) {
this.isSubcon = true; //HERE WHERE THE PROBLEM OCCURS (i think)
} else if (claims.admin) {
this.isWPC =true; //THIS ALSO
} else if (claims.subscriber) {
this.isBWG = true; //AND THIS ALSO
}
}
)
}
});
},
我正在使用 Firebase 自定义声明登录,并使用 Nuxt(模式:SPA)和 Vuetify 进行 UI。那么如何消除错误,以便将内容显示到导航抽屉?
提前谢谢你:))
【问题讨论】:
-
应该是,但我不确定如何在我的代码中真正实现它哈哈。我将
var that = this;放在if (claims.customer)上方并将this.isSubcon = true;更改为that.isSubcon = true;,但它仍然弹出相同的错误。也许你可以用代码告诉我如何解决它,好吗? -
哦,我也这样做
.then(this.isSubcon = true;)并删除它下面的 if-else 语句只是为了测试,它确实有效。 (因此,这样做实际上与您提供的文章有关)。但是如何在我的 if-else 语句中执行此操作并将我的v-if从false变为true。
标签: javascript firebase vue.js nuxt.js vuetify.js