Vue.js - Component is missing template or render function
Solution 1
When app.component(...)
is provided a definition object (the 2nd argument), it returns the application instance (in order to allow chaining calls). To get the component definition, omit the definition object and provide only the name:
app.component('home', { /* definition */ })
const Home = app.component('home')
const router = createRouter({
routes: [
{ path: '/', component: Home },
//...
]
})
Solution 2
FOR vue-cli vue 3
render function missed in createApp. When setting your app by using createApp function you have to include the render function that include App.
in main.js update to :
FIRST change the second line in javascript from:-
const { createApp } = Vue
to the following lines:
import { createApp,h } from 'vue'
import App from './App.vue'
SECOND
Change from :-
const app = createApp({})
to:
const app = createApp({
render: ()=>h(App)
});
app.mount("#app")
Solution 3
Make sure you have added <router-view></router-view>
in your #app
container.
Solution 4
The solution was simple on my side, I created a component that was empty, after filling in the template and a simple text HTML code, it was fixed.
Circuit Breaker
Updated on March 20, 2022Comments
-
Circuit Breaker about 2 years
In Vue 3, I created the following
Home
component, 2 other components (Foo
andBar
), and passed it tovue-router
as shown below. TheHome
component is created using Vue'scomponent
function, whereasFoo
andBar
components are created using plain objects.The error that I get:
Component is missing template or render function.
Here, the
Home
component is causing the problem. Can't we pass the result ofcomponent()
to a route object forvue-router
?<div id="app"> <ul> <li><router-link to="/">Home</router-link></li> <li><router-link to="/foo">Foo</router-link></li> <li><router-link to="/bar">Bar</router-link></li> </ul> <home></home> <router-view></router-view> </div> <script> const { createRouter, createWebHistory, createWebHashHistory } = VueRouter const { createApp } = Vue const app = createApp({}) var Home = app.component('home', { template: '<div>home</div>', }) const Foo = { template: '<div>foo</div>' } const Bar = { template: '<div>bar</div>' } const router = createRouter({ history: createWebHistory(), routes: [ { path: '/', component: Home }, { path: '/foo', component: Foo }, { path: '/bar', component: Bar }, ], }) app.use(router) app.mount('#app') </script>
See the problem in codesandbox.
-
AliN11 about 2 yearsYou can directly pass
App
tocreateApp
:createApp(App)