Skip to content

Weird v-bind attribute merging #11594

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
wenfangdu opened this issue Aug 14, 2020 · 6 comments
Closed

Weird v-bind attribute merging #11594

wenfangdu opened this issue Aug 14, 2020 · 6 comments

Comments

@wenfangdu
Copy link

wenfangdu commented Aug 14, 2020

Version

2.6.11

Reproduction link

https://codepen.io/wenfang/pen/VwaeOxW?editors=1111

Steps to reproduce

None

What is expected?

Since v-bind="{ foo: 'baz' }" is written after foo="bar", I expected the final DOM div has foo="baz"

What is actually happening?

The DOM div has foo="bar", is this intended?

@posva
Copy link
Member

posva commented Aug 14, 2020

HTML attributes are not ordered. Besides, specific attributes take precedence over v-bind="{}"

@posva posva closed this as completed Aug 14, 2020
@wenfangdu
Copy link
Author

wenfangdu commented Aug 14, 2020

@posva In this case, foo="bar" is a static attribute, v-bind="{ foo: 'baz' }" should take precedence, then how come the produced foo value is bar?

Also, in code like this

<template>
  <!-- eslint-disable -->
  <div :foo="`baz`" foo="bar"></div>
</template>

v-bind does not take precedence not all, the produced foo value is still bar.

@Justineo
Copy link
Member

I believe single attribute takes higher priority than the v-bind object binding. As it's more specific.

@posva
Copy link
Member

posva commented Aug 14, 2020

Yes, my bad, edited the comment

@wenfangdu
Copy link
Author

wenfangdu commented Aug 16, 2020

@posva
But in this case

<div v-bind="{ style: { height: '100px' } }" style="height: 300px;"></div>

Specific attribute does not take precedence over v-bind="{}", the result is style="height: 100px;"

@posva
Copy link
Member

posva commented Aug 16, 2020

Style and class have different behavior as the merge properties and dynamic ones have higher priority

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

No branches or pull requests

3 participants