Composition-api: Possible can i use composition api and vue-property-decorator typescript together?

Created on 18 Sep 2019  路  7Comments  路  Source: vuejs/composition-api

question

Most helpful comment

Yes, in main.js I've:

import Component from 'vue-class-component'

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

All 7 comments

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

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

Component.registerHooks([
  'setup'
])

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?

Yes, in main.js I've:

import Component from 'vue-class-component'

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

thank for your help :)

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!

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') }  })
Was this page helpful?
0 / 5 - 0 ratings

Related issues

sapphi-red picture sapphi-red  路  4Comments

SeregPie picture SeregPie  路  6Comments

swuecho picture swuecho  路  4Comments

zzachattack2 picture zzachattack2  路  3Comments

banricho picture banricho  路  3Comments