Home » vue » Vue component not showing up

Vue component not showing up

Posted by: admin November 26, 2021 Leave a comment

Questions:

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>
Answers:

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>