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

img tag attributes 'width, height' rendering with 0 #2801

Closed
Ryan2128 opened this issue Dec 11, 2020 · 4 comments
Closed

img tag attributes 'width, height' rendering with 0 #2801

Ryan2128 opened this issue Dec 11, 2020 · 4 comments

Comments

@Ryan2128
Copy link

Version

3.0.4

Reproduction link

https://codesandbox.io/s/pensive-wildflower-coe5n?file=/src/App.vue

Steps to reproduce

<img width="100%" height="100%" alt="Vue logo" src="./assets/logo.png" />
<img width="100px" height="100px" alt="Vue logo" src="./assets/logo.png" />

What is expected?

Expected as same as vue 2.

What is actually happening?

The value of width and height is 0


It looks very similar to #2677

@posva
Copy link
Member

posva commented Dec 11, 2020

The width and height attributes should be in pixels: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/width

@edison1105
Copy link
Member

@posva
setAttribute can avoid this problem.I don't know why we not use setAttribute here.
Is there any special reason?

@posva
Copy link
Member

posva commented Dec 12, 2020

it's because in Vue 3, attributes are set as properties: el.width = ... instead of el.setAttribute() if they can be set. For this specific case, one should use the style width and height, which are more appropriate.

Note that even the attribute should be in pixels without unit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-width

@edison1105
Copy link
Member

Ok,I got the point.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants