Vue 教程(十七)父子组件
父子组件
- 父组件下挂载一个子组件,子组件下还可以有子子组件。
代码实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>父子组件</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<parent-component></parent-component>
</div>
<script>
const childComponent = Vue.extend({
template: `
<div>
<h3>计算机系列丛书</h3>
<p>计算机|网络|人工智能</p>
</div>
`
});
const parentComponent = Vue.extend({
template: `
<div>
<h3>图书分类</h3>
<p>电子书|杂志期刊|原版书</p>
<child-component></child-component>
</div>
`,
components: {
'child-component':childComponent
}
})
const app = new Vue({
el:"#app",
components: {
'parent-component':parentComponent
}
})
</script>
</body>
</html>
– 以上为《Vue 教程(十七)父子组件》,如有不当之处请指出,我后续逐步完善更正,大家共同提高。谢谢大家对我的关注。
——厚积薄发(yuanxw)