Vue component not showing up

2019-08-16 22:35发布

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>

标签: vue.js
1条回答
做个烂人
2楼-- · 2019-08-16 23:29

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>

查看更多
登录 后发表回答