Skip to content

Commit

Permalink
fix(img): 修复图片宽高动态传导致样式没有更新的问题 (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongzhijie authored Sep 18, 2020
1 parent 080bf53 commit 327777d
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions packages/img/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ VueComponent({
round: Boolean,
mode: String,
lazyLoad: Boolean,
width: String,
height: String
width: {
type: String,
observer: 'setStyle'
},
height: {
type: String,
observer: 'setStyle'
}
},
data: {
style: ''
},
created () {
const { width, height } = this.data
let style = ''

style = isDef(width) && `width: ${addUnit(width)};`
style = isDef(height) ? style + `height: ${addUnit(height)}` : style

this.setData({ style })
this.setStyle()
},
methods: {
handleError ({ detail }) {
Expand All @@ -32,6 +32,15 @@ VueComponent({
},
handleLoad ({ detail }) {
this.$emit('load', detail)
},
setStyle () {
const { width, height } = this.data
let style = ''

style = isDef(width) && `width: ${addUnit(width)};`
style = isDef(height) ? style + `height: ${addUnit(height)}` : style

this.setData({ style })
}
}
})

0 comments on commit 327777d

Please sign in to comment.