Uncaught TypeError: Cannot set properties of undefined (setting 'isSubcon')

Uncaught TypeError: Cannot set properties of undefined (setting 'isSubcon')

这里需要一些帮助。

我希望我的导航抽屉根据登录用户 types/roles 显示不同的内容。

但是我遇到了这个错误(“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 Custom Claims 登录,Nuxt(模式:SPA)和 Vuetify 用于 UI。那么如何消除错误,以便将内容显示到我的导航抽屉中?

提前谢谢你:))

this 总是依赖于调用的 scope/object 并且属性 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
      }
    })
}