先在页面上引用一下插件js
1.首先获取到图片流
$(function() {
$('#img1').change(function() {
if (!this.files[0].type.match('image.*')) {
mui.alert("图片格式不正确!","提示", null);
return false;
}
var file = this.files[0];
lrz(file,{width:450,quality:0.7})//这里可以自定义一下图片压缩比率和压缩后的宽高
.then(function(rst){
var img = new Image();
img.src = rst.base64;//将压缩后的base64赋给img的src,然后可以赋给标签的src属性
base = rst.base64;