mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-05-20 21:49:14 +08:00
fix(Image): support set width & height dynamic (#2419)
fix #2415, fix #2392
This commit is contained in:
parent
4c09027afe
commit
f96f8450ba
@ -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) {
|
||||
|
@ -8,6 +8,7 @@
|
||||
<image
|
||||
wx:if="{{ !error }}"
|
||||
src="{{ src }}"
|
||||
webp
|
||||
mode="{{ mode }}"
|
||||
lazy-load="{{ lazyLoad }}"
|
||||
class="image-class van-image__img"
|
||||
|
Loading…
x
Reference in New Issue
Block a user