[英]Uncaught TypeError: Cannot set properties of undefined (setting 'isSubcon')
need some help here.在这里需要一些帮助。
I want my navigation drawer to display different contents based on the user types/roles of those who logged in.我希望我的导航抽屉根据登录者的用户类型/角色显示不同的内容。
But I encounter this error ("Uncaught TypeError: Cannot set properties of undefined (setting 'isSubcon'"). and my navigation drawer not displaying anything.但是我遇到了这个错误(“Uncaught TypeError:无法设置未定义的属性(设置'isSubcon'”)。我的导航抽屉没有显示任何内容。
my template
我的
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>
my script
我的
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
}
}
)
}
});
},
I'm using Firebase Custom Claims to log in and Nuxt (mode: SPA) with Vuetify for the UI.我正在使用 Firebase 自定义声明登录和 Nuxt(模式:SPA)和 Vuetify 的 UI。 So how can I remove the error, so that I can display the content to my nav drawer?
那么如何消除错误,以便将内容显示到导航抽屉?
Thank you in advance:))先感谢您:))
this
depends always on the scope/object called and both properties data: () => ({... })
and created()
seem to be properties of another object. this
始终取决于调用的范围/对象以及两个属性data: () => ({... })
和created()
似乎是另一个 object 的属性。 If you invoke it with:如果你调用它:
myObject.created();
then the solution below should do it.那么下面的解决方案应该可以做到。
created() {
let that = this;
firebase
...
.then(function ({ claims }) {
if (claims.customer) {
that.isSubcon = true; //HERE WHERE THE PROBLEM OCCURS (i think)
} else if (claims.admin) {
that.isWPC =true; //THIS ALSO
} else if (claims.subscriber) {
that.isBWG = true; //AND THIS ALSO
}
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.