<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
<script src="https://img.cdn.apipost.cn/mp/d44a51d7f879be97.webp"></script>
</head>
<body>
<div id="app">
<runoob ref='childa'></runoob>
</div>
<script>
var Child = {
template: '<h1>自定义组件!</h1>',
methods:{
sayname(v = 'undefined'){
console.log(`名字是:${v}`)
}
}
}
// 创建根实例
new Vue({
el: '#app',
components: {
// <runoob> 将只在父模板可用
'runoob': Child
},
mounted(){
//console.log(this.$refs.childa)
this.$refs.childa.sayname('yeyuan')
}
})
</script>
</body>
</html>