Vue: [2.0.0-rc2] Can't get $refs correctly

Created on 16 Aug 2016  ·  9Comments  ·  Source: vuejs/vue

Vue.js version

2.0 rc2

Reproduction Link

https://jsfiddle.net/1khxsgue/

Steps to reproduce

Just click run button, open console can find the error Cannot read property 'hello' of undefined

What is Expected?

The same code with 2.0 rc-1 https://jsfiddle.net/y35ot0du/ run without any error. We can access key testA inthis.$refs when components mounted hook is called .

Most helpful comment

@dalphyx, seems to me is behaving as expected. There is a v-if directive set to false which alters the component execution. At the moment of mounted the test component is not available.

All 9 comments

@dalphyx, seems to me is behaving as expected. There is a v-if directive set to false which alters the component execution. At the moment of mounted the test component is not available.

The fact that it does not work in -rc.2 anymore probably has to do with this:

Fixed

Fixed vdom patch errors on components with empty root (e.g. when root has v-if or transition)

https://github.com/vuejs/vue/commit/238f65dc71312c9e1b459771ce4373e25af32f10

@yyx990803 Is that a bug ?

@LinusBorg, if using v-if in a root node is forbidden, shouldn't it warn about when doing such?

Already deleted that comment, that was not entirely correct.

great! this bug wasted my a few hours to change the refs logic >.<

I'm having this issue on 2.4.4.

https://jsfiddle.net/TomKaltz/8q6e5tp5/

@TomKaltz please open a separate issue, thanks.

Maybe this is the same issue with #6632

@TomKaltz I'va having a very similar issue, did you manage to solve your issue ? If so, how ? If not, what did you end-up doing to acheive what you were going for ?

Was this page helpful?
0 / 5 - 0 ratings