question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: vm.refs is null

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
leeoniyacommented, Mar 4, 2017

i mean to test a plain refs obj that would be guaranteed not to be null

0reactions
leeoniyacommented, Mar 4, 2017

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found