JavaScript Vue.js refs are undefined, even though this.$refs shows theyre there

I have a reference to a component

 <Gmap ref="mapRef">

In mounted I am doing this, just to see the objects are available

 mounted(){
   let self = this
   console.log(self.$refs) // Shows the mapRef object reference
   console.log(self.$refs.mapRef) // returns undefined ???
 }

self.$refs shows...

  mapRef: VueComponent {_uid: 207, _isVue: true, $options: {…}, _renderProxy: Proxy, _self: VueComponent, …}

So then why does self.$refs.mapRef return undefined?? Even though its clearly there??

Answer:1

I had a similar problem getting a ref to a leaflet map instance, try waiting for the "nextTick"

mounted(){
  this.$nextTick(()=>{
    let self = this
    console.log(self.$refs) // Shows the mapRef object reference
    console.log(self.$refs.mapRef) // returns undefined ???
  });
}

see the docs for more- https://vuejs.org/v2/api/#vm-nextTick and https://vuejs.org/v2/api/#mounted

Answer:2

I solved this by using v-show instead of v-if.

I had the component inside a v-if statement.

 <div v-if="!isLoading"> 
   <GMap ref="mapRef" />
 </div>

I just changed that to v-show

<div v-show="!isLoading"> 
   <GMap ref="mapRef" />
 </div>

And now the object is available in mounted(). Still find it strange that the console.log(this.$refs) showed it being available as a key on this.$refs, even though it actually wasn't? Thats strange behaviour.

The other wierd thing was, that even if I tried to access this.$refs.mapRef in my data loading section, AFTER THE DATA WAS LOADED, (ie after isLoading=false), I still couldn't access it. Even though then, it should've been available because the v-if passed.

So v-show solved it, by just hiding the div, instead of not rendereding it. Stupid little workaround.

Answer:3

I developed in and published a game to the Play Store made with the Phaser gaming engine and Cordova. When this game is good enough, I would like to publish it to the App Store, but I've read that ...

I developed in and published a game to the Play Store made with the Phaser gaming engine and Cordova. When this game is good enough, I would like to publish it to the App Store, but I've read that ...

  1. will apple approve me for financing
  2. does apple approve apps over the weekend
  3. does apple approve webview apps
  4. does apple approve apps on weekends
  5. does apple approve of malwarebytes
  6. will apple card approved me

Django 1.8 and python 2.7. I am trying to update the location of a marker using jQuery and Ajax. My json object has only one array: [{"latitud": "55.75222", "ciudad": "Moscu", "longitud": "37.61556"...

Django 1.8 and python 2.7. I am trying to update the location of a marker using jQuery and Ajax. My json object has only one array: [{"latitud": "55.75222", "ciudad": "Moscu", "longitud": "37.61556"...

  1. update markers on google maps
  2. after effects update markers from source

OK I have full expectation of going down in flames for asking something stupid (or at least duplicate), but in the attached snippet, why do I have to use window.getComputedStyle to access styles ...

OK I have full expectation of going down in flames for asking something stupid (or at least duplicate), but in the attached snippet, why do I have to use window.getComputedStyle to access styles ...

A) Are there any resources of how to use server-side javascript without Node.js? B) Can a java-based server communicate with a javascript-based client? Both options are okay (I would be more happy ...

A) Are there any resources of how to use server-side javascript without Node.js? B) Can a java-based server communicate with a javascript-based client? Both options are okay (I would be more happy ...

  1. server side javascript
  2. server side javascript object
  3. server side javascript tutorial
  4. server side javascript frameworks
  5. server side javascript marketing cloud
  6. server side javascript injection
  7. server side javascript example
  8. server side javascript w3schools
  9. server side javascript is also known as
  10. server-side javascript has stopped working
  11. server side javascript tutorial pdf
  12. server side javascript is known as
  13. server side javascript rendering
  14. server-side javascript remote code execution
  15. server side javascript is also called as
  16. server-side javascript code injection
  17. server side javascript injection payloads
  18. server side javascript vs php
  19. server side javascript salesforce
  20. server side javascript injection example