Files
xhs-examples/xhs-mini-demos/component-case/image/image.js
2025-09-14 00:21:54 +08:00

95 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const __templateJs = require("./templates.js");
const __mergePageOptions = require("../../util/mergePageOptions.js");
Page(__mergePageOptions({
onShareAppMessage() {
return {
title: 'image',
path: 'page/component/pages/image/image'
};
},
data: {
apiData: {
content: '',
success: false,
fail: false,
complete: false
},
imageUrl: 'https://ci.xiaohongshu.com/83074709-0d05-4d1c-9d38-24a8e910d914',
webpImageURL: 'https://picasso-static.xiaohongshu.com/fe-platform/a30616b87ce2fcb1d9fd76a9e1b1e18d3b64aa53.webp',
array: [{
mode: 'scaleToFill',
text: 'scaleToFill不保持纵横比缩放图片使图片完全适应'
}, {
mode: 'aspectFit',
text: 'aspectFit保持纵横比缩放图片使图片的长边能完全显示出来'
}, {
mode: 'aspectFill',
text: 'aspectFill保持纵横比缩放图片只保证图片的短边能完全显示出来'
}, {
mode: 'top',
text: 'top不缩放图片只显示图片的顶部区域'
}, {
mode: 'bottom',
text: 'bottom不缩放图片只显示图片的底部区域'
}, {
mode: 'center',
text: 'center不缩放图片只显示图片的中间区域'
}, {
mode: 'left',
text: 'left不缩放图片只显示图片的左边区域'
}, {
mode: 'right',
text: 'right不缩放图片只显示图片的右边边区域'
}, {
mode: 'top left',
text: 'top left不缩放图片只显示图片的左上边区域'
}, {
mode: 'top right',
text: 'top right不缩放图片只显示图片的右上边区域'
}, {
mode: 'bottom left',
text: 'bottom left不缩放图片只显示图片的左下边区域'
}, {
mode: 'bottom right',
text: 'bottom right不缩放图片只显示图片的右下边区域'
}],
src: 'https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg'
},
resetApiData() {
this.setData({
apiData: {
success: false,
fail: false,
complete: false,
content: ''
}
});
},
updateApiData(content) {
const apiData = {
...this.data.apiData
};
apiData.success = true;
apiData.content = `${content}`;
this.setData({
apiData
});
},
onError(e) {
this.resetApiData();
this.updateApiData(JSON.stringify({
e,
msg: '图片加载失败'
}));
},
onLoad(e) {
this.resetApiData();
this.updateApiData(JSON.stringify({
e,
msg: '图片onLoad'
}));
setTimeout(() => {
this.removeSkeleton?.();
}, 1000);
}
}, __templateJs));