0👍
The error says Cannot read property 'loggedUser' of undefined
. Your code says this.loggedUser
, so I assume that this
is undefined. Try sending this
to it.
Common trope used to be that = this
in the outer context (inside mounted), or by sending it as an argument to the function (inside .then fn), though the more modern and simpler way is to simply use an arrow function () => {}
which allow you to access the outer scope in this example.
Either way, console.log(this)
until you have its reference. The problem is not having this
in scope.
0👍
Always Use arrow functions to don’t lose the context
mounted() {
...
.then((res) => {
this.groupedUsers = _.filter(res, (groupedUser) => {
return groupedUser.userId !== this.loggedUser.userId;
});
}
Source:stackexchange.com