vue中最简单的父组件调用子组件方法
通过ref属性绑定调用子组件的方法
父组件-----father.vue
<template>
<!----- 这是通过ref属性绑定 ------>
<child ref="child"></child>
<template>
mounted(){
//这是通过$refs获取,控制台打印显示子组件中的数据
this.$refs.child.childMethod()
}
子组件-----child.vue
data(){
return{
msg:'我是子组件的数据'
}
},
methods:{
childMethod(){
console.log(this.msg)
}
}