父组件调用子组件中的方法- this.$refs.xxx.子组件方法();

2022-10-21,,,,

组件中有一个说的方法 在父组件中去调用
当你点击的时候 去调用子组件中的方法

fu.vue
在父组件的方法中调用子组件的方法,
很重要 this.$refs.mychild.parentHandleclick();

{
<template>
<div>
<button @click="clickParent">点击 调用子组件</button>
<child ref="mychild"></child>
</div>
</template> <script>
import Child from "../zi/zi";
export default {
components: {
child: Child //key:value key是组件名称 value是被引入时的名称
},
methods: {
clickParent() {
this.$refs.mychild.parentHandleclick();
}
}
};
</script> }

zi.vue

{
<template>
<div ref="col">child</div>
</template> <script>
export default {
methods: {
parentHandleclick(e) {
console.log("我是子组件在说")
}
}
};
</script>
}

父组件调用子组件中的方法- this.$refs.xxx.子组件方法();的相关教程结束。

《父组件调用子组件中的方法- this.$refs.xxx.子组件方法();.doc》

下载本文的Word格式文档,以方便收藏与打印。