简体   繁体   English

未捕获的类型错误:无法设置未定义的属性(设置“isSubcon”)

[英]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.

相关问题 未捕获的类型错误:无法设置未定义的属性(设置“渲染”) - Uncaught TypeError: Cannot set properties of undefined (setting 'render') 未捕获的类型错误:无法设置未定义的属性(设置“全名”) - Uncaught TypeError: Cannot set properties of undefined (setting 'full_name') 未捕获的类型错误:无法设置未定义的属性(设置“innerHTML”) - Uncaught TypeError: Cannot set properties of undefined (setting 'innerHTML') Javascript 上的“未捕获的类型错误:无法设置未定义的属性” - "Uncaught TypeError: Cannot set properties of undefined" on Javascript 对于 onclick 中的 event.target - “Uncaught TypeError TypeError:无法设置未定义的属性(设置‘值’)” - For event.target in onclick - "Uncaught TypeError TypeError: Cannot set properties of undefined (setting 'value')" TypeError:无法设置未定义的属性(设置“转换”) - TypeError: Cannot set properties of undefined (setting 'transform') 类型错误:无法设置未定义的属性(设置“持续时间”) - TypeError: Cannot set properties of undefined (setting 'duration') 未捕获的类型错误:无法设置未定义的属性(设置“不透明度”)如何通过函数设置图像不透明度? - Uncaught TypeError: Cannot set properties of undefined (setting 'opacity') How to set image opacity via function? vue-session: Uncaught TypeError: 无法设置未定义的属性(设置'$session') - vue-session: Uncaught TypeError: Cannot set properties of undefined (setting '$session') 类型错误:无法设置未定义的属性(设置“srcObject”) - TypeError: Cannot set properties of undefined (setting 'srcObject')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM