Vuejs 使用官网上面的例子

vue.js报错 vue.js:597 [Vue warn]: Cannot find element: #app

问题: vue.js:597 [Vue warn]: Cannot find element: #app-4
检查了几遍代码没错,最后发现是引入vue的script必须放在body的末尾行。
解决: 引入vue的script必须放在body的末尾行。

------------------------------------------------------------------------------

1.使用vuejs 官网上面的例子,在控制台中发现了错误了,

VM2369 vue.js:2658 [Vue warn]: Unknown custom element: <todo-item> - did you register the component correctly? For recursive components, make sure to provide the "name" option. 
(found in root instance)

此原因是需要先注册组件,然后新建Vue

,顺序不能颠倒

2.源码:

<div id="app-7">
  <ol>
    <!-- Now we provide each todo-item with the todo object    -->
    <!-- it's representing, so that its content can be dynamic -->
    <todo-item v-for="item in groceryList" v-bind:todo="item"></todo-item>
  </ol>
</div>

Vue.component('todo-item', {
  props: ['todo'],
  template: '<li>{{ todo.text }}</li>'
})
var app7 = new Vue({
  el: '#app-7',
  data: {
    groceryList: [
      { text: 'Vegetables' },
      { text: 'Cheese' },
      { text: 'Whatever else humans are supposed to eat' }
    ]
  }
})

猜你喜欢

转载自blog.csdn.net/m0_37450089/article/details/83819413