vue 父组件调用子组件方法

父组件

clipboard.png

clipboard.png

clipboard.png

但一直报错说方法不存在,这是为什么?

阅读 4.1k
2 个回答

clipboard.png

应该把这个放到this.centerDialogVisible=true放到this.$refs.child.editDataFun()前面,因为需要显示弹窗才能获取到元素;

this.centerDialogVisible=true
this.$refs.child.editDataFun()

如果还不行,可以写

this.centerDialogVisible=true
this.$nextTick(() => {
    this.$refs.child.editDataFun()
})
  1. 检查子组件是否找到, 打印 this.$refs.child
  2. this.$refs.child.editDataFun()
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题