Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't access variable in v-if when defined in v-for on the same element #1165

Closed
rashfael opened this issue May 11, 2020 · 3 comments
Closed

Comments

@rashfael
Copy link

Version

3.0.0-beta.10

Reproduction link

https://jsfiddle.net/4qxok5gh/3/

Steps to reproduce

  • Run the reproduction

What is expected?

Reproduction should render:

2
3

What is actually happening?

A warning is printed in the console:

[Vue warn]: Property "a" was accessed during render but is not defined on instance.

I know that using v-for and v-if together is not recommended, but I could not find any rfc or issue in vue-next for a stricter enforcement of that best practice.

@yyx990803
Copy link
Member

yyx990803 commented May 11, 2020

This is expected behavior. v-if has higher priority than v-for so it doesn't have access to v-for scope: compiler output

Use <template v-for> for more explicit conditionals.

@rashfael
Copy link
Author

Okay, got it. That's a breaking change then? In Vue 2 it was the other way round.

@yyx990803
Copy link
Member

Yeah... technically. But using both on the same element has always been discouraged. Maybe we should add a warning for it.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants