這里需要一些幫助。
我希望我的導航抽屜根據登錄者的用戶型別/角色顯示不同的內容。
但是我遇到了這個錯誤(“未捕獲的型別錯誤:無法設定未定義的屬性(設定 '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。那么如何消除錯誤,以便將內容顯示到我的導航抽屜中呢?
先感謝您 :))
uj5u.com熱心網友回復:
this始終取決于呼叫的范圍/物件和兩個屬性,data: () => ({ ... })并且created()似乎是另一個物件的屬性。如果你呼叫它:
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
}
})
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/363614.html
