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

Possible can i use composition api and vue-property-decorator typescript together? #136

Closed
cuongdevjs opened this issue Sep 18, 2019 · 12 comments
Labels

Comments

@cuongdevjs
Copy link

No description provided.

@cuongdevjs
Copy link
Author

I use setup function in
export default class class_name extends Vue { setup() {} }
but it's not working?

@PatrykWalach
Copy link

Not sure if It'll help or not, but you should start by registering the hook,

Component.registerHooks([
  'setup'
])

@cuongdevjs
Copy link
Author

Not sure if It'll help or not, but you should start by registering the hook,

Component.registerHooks([
  'setup'
])

where i can place it? main.js right?

@rndmerle
Copy link

Yes, in main.js I've:

import Component from 'vue-class-component'

Component.registerHooks(['setup', 'beforeRouteUpdate', 'beforeRouteEnter', 'beforeRouteLeave'])

@cuongdevjs
Copy link
Author

thank for your help :)

@pikax
Copy link
Member

pikax commented Jun 16, 2020

Seems the issue is resolved, if not, please reopen or create a new issue.


Remember to use the forum or the Discord chat to ask questions!

@pikax pikax closed this as completed Jun 16, 2020
@CharlieBrownCharacter
Copy link

CharlieBrownCharacter commented Jul 9, 2020

I have done the following:

main.js

import Component from 'vue-class-component';
// On why we do this visit: https://github.com/vuejs/composition-api/issues/136
Component.registerHooks(['setup']);

Then on my component:

import { Component, Vue } from 'vue-property-decorator';

@Component
export default class MyComponent extends Vue {
   setup() {
       console.log('setup function executed');
   }
}

But the console log never shows. Any idea?

If I move the setup method to the options it works:

@Component({ setup() { console.log('hello from setup') }  })

@BernhardSchlegel
Copy link

BernhardSchlegel commented Feb 11, 2021

Hey @CharlieBrownCharacter since setup has no this available ("Because the component instance is not yet created when setup is executed, there is no this inside a setup option.", source: official doc) I think it makes sense for it to reside in the @Component decorator and not in the actual class where you might be tempted to use an (undefined) this operator.

@fobdy
Copy link

fobdy commented Feb 12, 2021

Unfortunately, I have problems with type validation in that scenario using Vue 2 with @vue/composition-api
изображение

Any thoughts on that, guys?

@bogdan-kuternoga
Copy link

bogdan-kuternoga commented Feb 25, 2021

@pikax ,
Unfortunately in our project we have the same issue as @fobdy described.
So could you please reopen this ticket?

Btw, as for me setup as a static method would be the best solution.

Thanks

@pikax
Copy link
Member

pikax commented Feb 25, 2021

That seems to be an issue using the vue-property-decorator which is not maintained or supported by us, if you can reproduce using the defineComponent provided by @vue/composition-api I can have a look on it.

@yoyo930021
Copy link
Member

Unfortunately, I have problems with type validation in that scenario using Vue 2 with @vue/composition-api
изображение

Any thoughts on that, guys?

TypeScript can't support any method for let decorator effect type.
So you should consider other ways.
Maybe vuejs/vue-class-component#465?

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

No branches or pull requests

10 participants