composition-api: the `components` option in createComponent() doesn't support vue2 options

After I updated to 2.2.0, I found that when I run npm run serve, the develop server console ouput is just like this:

And I cannot run npm run build, the process will crash because of the error.

However, the browser console didn’t show any errors, and it can run normally. So I cannot simply reproduce it online… In fact, I just create the project with vue-cli3, and change App.vue to this:

<script lang="ts">
    import {createComponent} from 'vue-function-api';
    import HelloWorld from './components/HelloWorld.vue';

    export default createComponent({
        components: {HelloWorld}
    });
</script>

I read the RFC again, and maybe 3.x will continue to be compatible with the 2.x components option?

And when I went back to 2.1.2, the type error disappeared. Did I go something wrong? Or how can I import and use *.vue components correctly?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 24 (10 by maintainers)

Most upvoted comments

Casting as any will break all the types support. One of the workarounds right now is to take all the keys, except props an setup outside the createComponent function.

export default {
  components: {
  },
  ...createComponent({
    setup(props) {
    },
    props: {
    }
  })
}

createComponent only support using with an inline render function return by setup now.

Why so? By spec, its not written anywhere that setup() and other properties cannot be used together (especially component and name for which I don’t see a clear alternative). There even is an example of mixed-usage where setup() and data are used together.

@liximomo Seems that on @vue/composition-api 0.1., components work BUT not for lazy ones :

Classic import image

Lazy loading image

image

I’m confused. Is the final behavior going to no longer allow name and components properties within the createComponent function? This is important to know so that I can either downgrade the package for the time being or begin migrating to a newer standard.

You are welcome to work on solving this challebge.

the name option in createComponent() how to dealwith?
Is there any other way besides setting any type?

export default createComponent({
   name: 'componentName'
})

@liximomo