父组件访问子组件 c h i l d r e n , children, children,ref
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/vue.js"></script>
</head>
<body>
<div id="app">
<cpn></cpn>
<cpn ref="f"></cpn>
<cpn ref="r"></cpn>
<button @click="btnclick">按钮</button>
</div>
<template id="temp">
<div>
哈哈
</div>
</template>
<script>
const app = new Vue({
el:'#app',
data:{
},
methods:{
btnclick(){
// console.log(this.$children);
// this.$children[0].showmessage();
console.log(this.$refs.r);
}
},
components:{
cpn:{
template:'#temp',
methods:{
showmessage(){
console.log("按住啦北鼻")
}
}
}
}
})
</script>
</body>
</html>