方法一:使用$refs查找,$refs有些类似dom方法getElementById,可以这么理解
//子组件
<template>
<div>
child
</div>
</template>
<script>
export default {
name: "child",
props: {
type: String,
},
methods: {
childFn(e) {
console.log(e)
}
}
}
</script>
//父组件
<template>
<div>
<button @click="clickParent">点击</button>
<child :type="type" ref="mychild"></child>
</div>
</template>
<script>
import Child from './child';//引入子组件
export default {
name: "parent",
data(){
return{
type:'123'
}
},
components: {
child: Child
},
methods: {
clickParent() {
this.$refs.mychild.childFn("父组件触发子组件方法");
}
}
}
</script>