foxbenjaminfox/vue-async-computed

this.$asyncComputed.name.update() doesn't allow to access Vue this.

KubasGC opened this issue · 4 comments

I'm using async computed property like this:

asyncComputed:
        {
            perms:
            {
                lazy: true,
                async get()
                {
                    return (await DelegationsService.getPermissions(this.$route.params.delegationId)).data;
                },
                default:
                {
                    accept: false,
                    edit: false,
                    settlement: false,
                    isOwner: false
                }
            }
        }

It works fine, but when I'm using function this.$asyncComputed.perms.update() inside method, I have got an error called that I have no access to this entity,

I'm trying to reproduce the bug, but I'm not quite managing. Do you have a minimal replication of the issue you could share? Or even just more detail about what causes the error.

I ran into this problem as well. Here's a code pen I made showing the issue. When update is called, the get function runs twice, but the first time this points to the window, not the Vue instance.
https://codepen.io/yancyknight/pen/LqOEpR?editors=1010

OK, now I see. This is actually a duplicate of #53, which was fixed in #54, which was included in v3.5.1. If you upgrade to the latest version of vue-async-computed, that will fix the problem.

@yancyknight: thanks for making the code pen with the demonstration of the issue. It was very helpful in making it clear what exactly the problem was, and how it was the same as issue #53.

The new version works great, thank you!