父组件: 在子组件中加上ref即可通过this.$refs.ref.method调用
<template>
<div @click="parentMethod">
<children ref="c1"></children>
</div>
</template>
<script>
import children from 'components/children/children.vue'
export default {
data(){
return {
}
},
computed: {
},
components: {
'children': children
},
methods:{
parentMethod() {
console.log(this.$refs.c1) //返回的是一个vue对象,所以可以直接调用其方法
this.$refs.c1.childMethod();
}
},
created(){
}
}
</script>
vue 父调用子的方法
最新推荐文章于 2022-05-12 15:09:47 发布
本文介绍如何在Vue.js中实现父组件调用子组件的方法。通过使用ref属性,父组件可以轻松地访问并调用子组件的特定方法。
4万+

被折叠的 条评论
为什么被折叠?



