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: {
|
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) {
|
||||||
|
@ -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"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user