Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spread from function return unsupported in object options #6

Open
CyberAP opened this issue Jun 24, 2019 · 0 comments
Open

Spread from function return unsupported in object options #6

CyberAP opened this issue Jun 24, 2019 · 0 comments

Comments

@CyberAP
Copy link

CyberAP commented Jun 24, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant