Vue js Component 入れ子構造について
コンポーネントについての過去記事は以下
kirikko-scondcube.hatenablog.com
コード
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Vueの練習</h1>
<div id="app">
<h2>{{message}}</h2>
<list></list>
</div>
<script>
Vue.component('title-com',{
data(){
return{
}
},
template:`<h3>{{text}}</h3>`
})
return {
items:[
{id:1, name:'taro' },
{id:2, name:'ziro' },
{id:4, name:'yon' },
{id:5, name:'goro' },
]
}
},
template:`
<div>
<title-com></title-com>
<ul>
<li v-for='item in items' :key='item.id'>
{{item.name}}
</li>
</ul>
</div>
`
})
new Vue({
el:'#app',
data:{
message:'コンポーネントの練習'
}
})
</script>
</body>
</html>
title-comのコンポーネントを作成→そのコンポーネント名をlistコンポーネントのtemplate内で記述
するとlistコンポーネント内でtitle-comコンポーネントが実行される。
表示結果