uView
uView copied to clipboard
关于裁剪头像问题
onLoad(option) { let rectInfo = uni.getSystemInfoSync(); this.width = rectInfo.windowWidth; this.height = rectInfo.windowHeight - this.bottomNavHeight; this.cropperOpt.width = this.width; this.cropperOpt.height = this.height; this.cropperOpt.pixelRatio = rectInfo.pixelRatio;
if (option.destWidth) this.destWidth = option.destWidth;
if (option.rectWidth) {
let rectWidth = Number(option.rectWidth);
this.cropperOpt.cut = {
x: (this.width - rectWidth) / 2,
y: (this.height - rectWidth) / 2,
width: rectWidth,
height: rectWidth
};
}
this.rectWidth = option.rectWidth;
如果跳转时不传参 将不会初始化成功cut对象 x/y/width/height的值分别为undefined 和 NAN 应该把应该在判断option.rectWidth时先判断有没有值 没有就使用初始值 所以加一句下面的代码即可初始化成功: option.rectWidth = option.rectWidth || this.rectWidth
@Liuminke1996 感谢大牛,碰到同样的问题
@Liuminke1996 正解!感谢!🧔