composition-api-converter icon indicating copy to clipboard operation
composition-api-converter copied to clipboard

Spread from function return unsupported in object options

Open CyberAP opened this issue 6 years ago • 0 comments

Object spread is not currently supported and probably could be handled with some ugly code (unfortunately).

Input:

  const computed = { value() { return this.count + 1;  } };

  export default {
    props: {
      count: Number,
    },
    computed: {
      ...computed,
    }
  }

Could be:

import { computed } from 'vue';

const _computed = { value() { return this.count + 1; } };

export default {
  setup(props, context) {
    const ctx = { ...props, ...context };
    return {
      ...Object.keys(_computed).reduce((acc, key) => {
        acc[key] = computed(_computed[key].bind(ctx))
        return acc;
      }, {})
    }
  }
}

The same applies to methods and data.

CyberAP avatar Jun 24 '19 14:06 CyberAP