user88831
user88831

Reputation: 327

Access child ref from parent

I'm trying access child ref from parent. I tried already in this ways:

1. PARENT

someMethod() { 
   console.log(this.$refs.someChildCompontentRef.$refs) // {} 
}

CHILD

mounted(){ 
   this.$emit('setRef', $this.refs.someRef); 
}

PARENT

setRef(ref) { 
  console.log(ref) // undefinded don't know why? 
}

Upvotes: 0

Views: 224

Answers (1)

Ilijanovic
Ilijanovic

Reputation: 14914

My guess:

The virtual DOM is already builded up but the real DOM isnt. So you need to wait till its builded up:

async mounted(){ 
   await this.$nextTick()
   this.$emit('setRef', $this.refs.someRef); 
}

Upvotes: 1

Related Questions