fix(Image): support set width & height dynamic (#2419)

fix #2415, fix #2392
This commit is contained in:
rex 2019-11-28 14:38:33 +08:00 committed by GitHub
parent 4c09027afe
commit f96f8450ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 8 deletions

View File

@ -18,8 +18,14 @@ VantComponent({
props: { props: {
src: String, src: String,
round: Boolean, round: Boolean,
width: null, width: {
height: null, type: null,
observer: 'setStyle'
},
height: {
type: null,
observer: 'setStyle'
},
radius: null, radius: null,
lazyLoad: Boolean, lazyLoad: Boolean,
useErrorSlot: Boolean, useErrorSlot: Boolean,
@ -27,7 +33,8 @@ VantComponent({
showMenuByLongpress: Boolean, showMenuByLongpress: Boolean,
fit: { fit: {
type: String, type: String,
value: 'fill' value: 'fill',
observer: 'setMode'
}, },
showError: { showError: {
type: Boolean, type: Boolean,
@ -54,18 +61,18 @@ VantComponent({
}, },
mounted() { mounted() {
this.init(); this.setMode();
this.setStyle();
}, },
methods: { methods: {
init() { setMode() {
this.setData({ this.setData({
mode: FIT_MODE_MAP[this.data.fit], mode: FIT_MODE_MAP[this.data.fit],
style: this.getStyle()
}); });
}, },
getStyle() { setStyle() {
const { width, height, radius } = this.data; const { width, height, radius } = this.data;
let style = ''; let style = '';
@ -82,7 +89,7 @@ VantComponent({
style += `border-radius: ${addUnit(radius)};`; style += `border-radius: ${addUnit(radius)};`;
} }
return style; this.setData({ style });
}, },
onLoad(event) { onLoad(event) {

View File

@ -8,6 +8,7 @@
<image <image
wx:if="{{ !error }}" wx:if="{{ !error }}"
src="{{ src }}" src="{{ src }}"
webp
mode="{{ mode }}" mode="{{ mode }}"
lazy-load="{{ lazyLoad }}" lazy-load="{{ lazyLoad }}"
class="image-class van-image__img" class="image-class van-image__img"