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

View File

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