Home > Mobile >  No property 'component' error after creating new project with vue-cli
No property 'component' error after creating new project with vue-cli

Time:12-26

This part of the documentation of Vue3 says that it should be possible to call a function component on the object returned by createApp.

I created a project using vue-cli with vue create myApp.
I selected Vue3 and added typescript to the project.

The generated project contains a file named main.ts where createApp is used.
I tried to use the component method as indicated in the doc and got the following error.

ERROR in src/main.ts:6:5
TS2339: Property 'component' does not exist on type 'ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>>'.
// main.ts
import { createApp } from 'vue'
import App from './App.vue'

const app = createApp(App).mount('#app')

app.component("er", {})

Is there more setup to do in order to use all feature of Vue ?

CodePudding user response:

createApp(App) and createApp(App).mount('#app') are different object. The former is Vue instance, the latter is component instance.

It should be:

const app = createApp(App)
app.component("er", {})

const vm = app.mount('#app')
  • Related