Skip to content

Commit

Permalink
fix(image): enable dynamic dimension (#2050)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeJim authored May 30, 2023
1 parent 43dbad6 commit f570486
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/image/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,9 @@ export default class Image extends SuperComponent {
lifetimes = {
attached() {
const { width, height } = this.data;
let innerStyle = '';
this.update();

if (width) {
innerStyle += `width: ${addUnit(width)};`;
}
if (height) {
innerStyle += `height: ${addUnit(height)};`;
}
this.setData({
innerStyle,
});
this.update();
this.calcSize(width, height);
},
};

Expand All @@ -48,6 +39,9 @@ export default class Image extends SuperComponent {
if (this.preSrc === this.properties.src) return;
this.update();
},
'width, height'(width, height) {
this.calcSize(width, height);
},
};

methods = {
Expand Down Expand Up @@ -84,6 +78,20 @@ export default class Image extends SuperComponent {
this.triggerEvent('error', e.detail);
},

calcSize(width, height) {
let innerStyle = '';

if (width) {
innerStyle += `width: ${addUnit(width)};`;
}
if (height) {
innerStyle += `height: ${addUnit(height)};`;
}
this.setData({
innerStyle,
});
},

update() {
const { src } = this.properties;
this.preSrc = src;
Expand Down

0 comments on commit f570486

Please sign in to comment.