kaorun343/vue-property-decorator

How to convert getter to computed property?

Opened this issue · 1 comments

Hi. I use vue + vuex + ts + nuxt + vue-property-decorator in my project.

I have getter like this:

public get polls(): PollData[] {
	return this.$store.getters[`polls/getPolls`];
}

It will be transpiled to typical getter:

get polls() {
	return this.$store.getters[`polls/getPolls`];
}

How I convert it to computed property instead?
I don't need a setter for it.

nros commented

vue-class-component is doing this.
see: https://github.com/vuejs/vue-class-component/blob/16433462b40aefecc030919623f17b0ec9afe61c/src/component.ts#L54

All properties of your class are copied to the configuration object for Vue. There is a check. If the property consists of a getter/setter, it is added to the computed data.

} else if (descriptor.get || descriptor.set) {
      // computed properties
      (options.computed || (options.computed = {}))[key] = {
        get: descriptor.get,
        set: descriptor.set
      }
    }

Since this is done at runtime, you will not see this in your transpiled code.