vue233/10-组件化开发/08-父子组件的访问/父组件访问子组件($ref-$children)/父组件访问子组件$children.html

52 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">
<apps></apps>
<button @click="Clickme()">点击我</button>
</div>
<template id="tpl">
<div>
<h1>这是子组件</h1>
</div>
</template>
</body>
<script src="../../../00-tools/JavaScript/vue.js"></script>
<script>
new Vue({
el:"#app",
methods: {
Clickme(){
this.$children[0].ChildItems()
for (let i =0;i<this.$children[0].list.length;i++){
this.$children[0].list[i]=i+2-1/2
}
console.log(this.$children[0].list);
}
},
components:{
'apps':{
template:"#tpl",
data(){
return{
list:[0,1,2,3,5,6,7,3,1]
}
},
methods: {
ChildItems(){
let item=1
console.log("这是子组件函数");
console.log(this.list);
}
},
}
}
})
</script>
</html>