vue component为什么不显示?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <ol>
        <!-- 创建一个 todo-item 组件的实例 -->
        <todo-item></todo-item>
    </ol>

    <script src="https://unpkg.com/vue"></script>
    <script>
        Vue.component('todo-item', {
            template: '<li>这是个待办项</li>'
        })
    </script>
</body>
</html>

初学vue,为什么我这边显示的是一个空白页面,组件模板的写法是错的么?

阅读 8k
2 个回答

html里面是这样的

<div id='app'>
<v-header></v-header>
</div>

js 是这样的

    Vue.component('vHeader', {
          template: '<div>A custom component!</div>'
        })

    new Vue({
        el:'#app',
    })

。。。因为你还没有一个vue实例对象,也就是主模板,也没有挂载到文档中。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题