0

When using the Composition API with Class Components in Vue 3 and when using Typescript, how can properties be defined in the setup method? For example:

export default class Test extends Vue {
    myAContext = setup(()=> {...})
    myBContext = setup(()=> {...})
} 

In this code, I do not want to use the Options attribute, and neither would I like to use the @Prop attribute that comes in the vue-property-decorators package as I believe they are part of the Options API and I think it would not be a good practice to mix these two APIs together.

Correct me if I am wrong.

Edit: To better clarify, how can I define Props that are scoped to the context (setup method lambda)?

12
  • It's not possible to declare props from the setup() hook. Commented Feb 17, 2022 at 4:16
  • @tony19: When using the vue-class-components, does that library use composition api or option api? Commented Feb 17, 2022 at 4:20
  • @tony19: I mean does the Options attribute mean Option API? The name is a bit confusing. From my perspective (after posting the question), it has nothing to do with the option API. Commented Feb 17, 2022 at 4:22
  • Yes, it uses the Options API, and there's no reason to avoid using that API. Commented Feb 17, 2022 at 4:25
  • @tony19: Do you mean using the Options API together with the Composition API is not a bad thing? Commented Feb 17, 2022 at 4:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.