Reputation: 2887
I'm trying to run the code from Vue docs about components, but the component doesn't show up. Why not?
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="app">
<todo-item></todo-item>
</div>
<script>
Vue.component('todo-item', {
template: '<li>This is a todo</li>'
})
</script>
</body>
</html>
Upvotes: 1
Views: 18484
Reputation: 21485
You need to create a Vue instance, and tell it where in the page its root element belongs (#app
in this case):
Vue.component('todo-item', {
template: '<li>This is a todo</li>'
})
var app = new Vue({
el: '#app'
});
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<div id="app">
<todo-item></todo-item>
</div>
Upvotes: 3