TypeError: vm.refs is null
See original GitHub issueI have refs in my app which, in some circumstances, are not created (because the node they reference is not required). But other code tests for these refs, doing the obvious:
if(vm.refs.xyz) {
...
}
This, of course, breaks when there are no refs at all and the refs
object is null.
Would it be undesirable to always have a refs
object? Otherwise, I am just ensuring it exists in my render function.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Vue.js refs are undefined, even though this.$refs shows theyre ...
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" ...
Read more >Property 'refs' does not exist on type 'SetupContext' · Issue #319
I just started to use TypeScript and Composition API in my project. For "defineComponent" function, I get an error Property 'refs' does not ......
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 retu…
Read more >Error in render: "TypeError: _vm.selectedProductDetails is null ...
I find workaround. I created method: getSelectedProductDetailsId: function (){ return this.selectedProductDetails?.id }. and it work :).
Read more >Subtle difference between ref(null) and ref({}) : r/vuejs - Reddit
Maybe it's a Type Error where if you pass the object some attributes are expected. I'm stabbing in the dark here for I'm...
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 FreeTop 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
Top GitHub Comments
i mean to test a plain refs obj that would be guaranteed not to be null
i’m gonna close this. if you really want this behavior, you can simply extend the ViewModel prototype with your own ES5 getter (via
Object.defineProperty
[1]) to get the desired effect: https://jsfiddle.net/v1ubxq7o/[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty