使用vue-cli创建新项目后没有属性 'component'错误
No property 'component' error after creating new project with vue-cli
This part of the documentation of Vue3 表示应该可以在 createApp
.
返回的对象上调用函数 component
我使用 vue-cli 和 vue create myApp
创建了一个项目。
我选择了Vue3并在项目中添加了typescript。
生成的项目包含一个名为 main.ts
的文件,其中使用了 createApp
。
我尝试使用文档中指示的 component
方法,但出现以下错误。
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", {})
是否需要进行更多设置才能使用 Vue 的所有功能?
createApp(App)
和 createApp(App).mount('#app')
是不同的对象。前者是Vue实例,后者是组件实例。
应该是:
const app = createApp(App)
app.component("er", {})
const vm = app.mount('#app')
This part of the documentation of Vue3 表示应该可以在 createApp
.
component
我使用 vue-cli 和 vue create myApp
创建了一个项目。
我选择了Vue3并在项目中添加了typescript。
生成的项目包含一个名为 main.ts
的文件,其中使用了 createApp
。
我尝试使用文档中指示的 component
方法,但出现以下错误。
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", {})
是否需要进行更多设置才能使用 Vue 的所有功能?
createApp(App)
和 createApp(App).mount('#app')
是不同的对象。前者是Vue实例,后者是组件实例。
应该是:
const app = createApp(App)
app.component("er", {})
const vm = app.mount('#app')