第一步:
在子組件注冊一個方法
比如
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>