創建組件使用Vue.component()方法,它是創建的全局組件
- 參數1表示組件名字
- 參數2表示組件配置項
<div id="app">
<!-- 2. 使用組件,像html標簽一樣 -->
<index></index>
<index-b></index-b>
</div>
<script>
Vue.component('index', {
// template屬性指定組件模板
template: '<div>這是首頁<index-b></index-b></div>'
})
// 注意組件命名如果使用駝峰命名法,上面在頁面中使用的時候就需要改成連字符⭐
Vue.component('indexB', {
// template屬性指定組件模板,模板只能有一個根節點⭐
template: '<div>這是首頁B</div>'
})
var vm = new Vue({
el: '#app',
data: {
}
})
</script>