Skip to content

fix #255: Add new rule require-v-if-else-key #1845

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

Closed
wants to merge 7 commits into from

Conversation

doug-wade
Copy link
Contributor

This one's probably a smidge later than it could have been -- I can't find it in the style guide anymore -- but better late than never?

@FloEdelmann FloEdelmann linked an issue Apr 13, 2022 that may be closed by this pull request
Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this rule. I have a few suggestions.

doug-wade and others added 2 commits April 15, 2022 23:01
Co-authored-by: Flo Edelmann <florian-edelmann@online.de>
Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run npm run update to update the docs and fix all lint issues.

Other than that, this looks good to me. Thanks!

</template>
</div>
</template>
`
Copy link
Member

@ota-meshi ota-meshi Apr 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this valid? I think this should be reported.

Copy link
Contributor Author

@doug-wade doug-wade Apr 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must have misinterpreted your comment:

Note that vue2 does not allow you to place a key in .

If no keys are allowed, mustn't we allow templates without keys?

Copy link
Member

@ota-meshi ota-meshi Apr 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Vue2 need to put the key on the actual element, not the <template>.

e.g.

<template v-if="foo">
  <div key="a" />
</template>
<template v-else>
  <div key="b" />
</template>
<template v-if="foo">
  <div key="a" />
  <div key="b" />
</template>
<template v-else>
  <div key="c" />
  <div key="d" />
</template>

However, with Vue3 you can do the following:

<template v-if="foo" key="a">
  <div />
</template>
<template v-else key="b">
  <div />
</template>
<template v-if="foo" key="a">
  <div />
  <div />
</template>
<template v-else key="b">
  <div />
  <div />
</template>

@doug-wade
Copy link
Contributor Author

Heya, things have gotten pretty busy for me, and I don't think I'll have time to clean this one up in the near future. I'm going to close this one for now.

@doug-wade doug-wade closed this May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule proposal: v-if-else-key
3 participants