admin-vue/10-组件化开发/09-组件插槽使用/复习父子访问.html

55 lines
1.1 KiB
HTML

<!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>Document</title>
</head>
<body>
<div id="app">
<div>
<h1>这是父组件</h1>
<ul v-for="lists in content">
<li>{{lists}}</li>
</ul>
<button @click="Clickme()">点击我获取数据</button>
</div>
<br>
<br>
<apps ref="children"></apps>
</div>
<template id="tpl">
<div>
<h1>这是子组件</h1>
<ul v-for="item in list">
<li>{{item}}</li>
</ul>
</div>
</template>
</body>
<script src="../../JavaScript/vue.js"></script>
<script>
new Vue({
el:"#app",
data:{
content:[]
},
methods: {
Clickme(){
this.content= this.$refs.children.list;
}
},
components:{
'apps':{
template:"#tpl",
data(){
return {
list:["这是第一个内容","这是第二个内容","这是第三个内容"]
}
}
}
}
})
</script>
</html>