foxbenjaminfox/vue-async-computed

"this.$options is undefined" is being raised when using vue async computed

EO2875 opened this issue · 0 comments

At some point in my component I wanted to do this:

export const {
    methods: {
        mymethod() {
            this.$options.data // Does not raise error
            const originalData = this.$options.data() // TypeError: this.$options is undefined
        }
    },
}

I checked the console and this.$options.data gets overwritten by vue-async-computed to be vueAsyncComputedInjectedDataFn, and the error is in this line:

    for (var key in asyncComputed) {
        var item = this.$options.asyncComputed[key];

In my component, this solves the error:

mymethod() {
    this.$options.data.call(this)
}

However, I think this problem should be fixed from vue-async-computed's side, not from the developer side. As I understand, the Vue API allows us to simply call this.$options.data()