[英]Uncaught TypeError: Cannot set properties of undefined (setting 'render')
[英]Uncaught TypeError: Cannot set properties of undefined (setting 'isSubcon')
在这里需要一些帮助。
我希望我的导航抽屉根据登录者的用户类型/角色显示不同的内容。
但是我遇到了这个错误(“Uncaught TypeError:无法设置未定义的属性(设置'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。 那么如何消除错误,以便将内容显示到导航抽屉?
先感谢您:))
this
始终取决于调用的范围/对象以及两个属性data: () => ({... })
和created()
似乎是另一个 object 的属性。 如果你调用它:
myObject.created();
那么下面的解决方案应该可以做到。
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.