第一步:
在子组件注册一个方法
比如
showSure(){
this.show=true
console.log('成功调用子组件方法')
},
然后再父组件中
<button @click="getChild">点击调用子组件</button>3
<!-- 子组件注册个ref -->
<toast ref="child1"></toast>
<script>
import toast from './toast'//引入子组件
export default {
components:{toast},//注册组件
name:'login',
methods:{
getChild(){
this.$refs.child1.showSure() //child1是写在子组件上的属性 showSure()是子组件的方法名
}
}
}
</script>