uView icon indicating copy to clipboard operation
uView copied to clipboard

关于裁剪头像问题

Open 0xssw opened this issue 4 years ago • 2 comments

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

0xssw avatar Jun 09 '20 14:06 0xssw

@Liuminke1996 感谢大牛,碰到同样的问题

EverythingIsNothing avatar Jun 12 '20 08:06 EverythingIsNothing

@Liuminke1996 正解!感谢!🧔

AmosHuKe avatar Aug 07 '20 06:08 AmosHuKe