小程序开发记录

  • 小程序需要用到正则的时候 要这么写
var reg = getRegExp('-', 'gi'); //wxs的正则 
timestamp = timestamp.replace(reg, '/'); 
  • 小程序图片自适应
* 方法一:
	.imgs{
		width: 100%;
	}
	使用widthFix 就能自适应
	<image class="imgs" style="width: 100%;"  bindload="imageLoad" src="{{item}}" mode="widthFix" />

*方法二:
设置隐藏 使用bindload

imageLoad: function (e) {

	var width = e.detail.width,//图片宽度
		height = e.detail.height;
	var ratio  = width / height;
	var screenWidth = app.globalData.systemInfo.screenWidth;

	height = (screenWidth - 30) / ratio; 
	//30是左右边距

	this.setData({
		height,
	});
},
//用一个image 做隐藏
<image  style="width: 100%;" class="hidden" bindload="imageLoad" src="{{item}}" mode="widthFix" />