抱怨身处黑暗,不如提灯前行。——刘同

首先是官方文档

这里使用ref属性去访问子元素

1
<hello-world ref="helloWorld" msg="Hello World"></hello-world>

然后打印一下

1
console.log(this.$refs.helloWorld);

image-20211102202015275

可以看到成功获取到

再到子组件定义一个方法:

image-20211102202118934

父组件访问:

image-20211102202132266

效果:

image-20211102202107779