this.$refs.key return undefined after hot reload
See original GitHub issueVersion
2.4.2
Reproduction link
No reproduction link, need hot reload…
Steps to reproduce
Use this vue file:
<template>
<div>
<div ref="test"></div>
</div>
</template>
<script>
export default {
name: 'test',
mounted () {
setInterval(() => {
console.log(this.$refs.test)
}, 2000)
}
}
</script>
<style>
</style>
Run it then edit the file, change this.$refs.test
to this.$refs.test.clientWidth
, save and watch the console.
What is expected?
After hot reload, display the width of the div
.
What is actually happening?
After hot reload, return undefined
, then the width of the div
.
It the same if you use a $refs
in a function of an event listener. Even if you destroy it in deforeDestroy
.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Vue.js refs are undefined, even though this.$refs shows theyre ...
mapRef in mounted() tried to wrap it with setTimeout() and 2 layers of this.$nextTick() . It works only on hot reload, but no...
Read more >[SOLVED] This.$refs.key returns undefined when it really is
I am using Vue 2.0 with Webpack. When I say console.log(this.$refs) (inside created() method inside a low level component) it returns:
Read more >Focus management with Vue refs - Learn web development
Now when you activate the "Edit" button and then cancel or save your changes via the keyboard, focus should be returned to the...
Read more >Understanding refs in Vue - LogRocket Blog
According to what we already know about Vue ref s, they return an object, but judging by the undefined response, something is wrong....
Read more >useForm - watch - Simple React forms validation
When defaultValue is not defined, the first render of watch will return undefined because it is called before register . It's recommend to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Wait. This is not about interval, he just want to show that
$refs.key
will beundefined
. It seems like after hot-reloading, reference on$refs.key
is missing. I still have this problem with Vue CLI 3.0.0-rc.11Yes, unfortunately I live this issue. I’am using this.$nextTick and also setTimeout, both of them are same result. I write console.log this.$refs on nextTick and it returns id of it in object key but the value is undefined.