ctx.drawImage(img, 0, 0, targetWidth, targetHeight);
let base64 = canvas.toDataURL('image/png', 0.9);
resolve(base64);
}, false);
}))
}
}
调用:
test.js
onChangeImg = async (files, type, index) => {
let previous = this.props.imagePicker.files;
if(type === "add") {
let result = miniSize(files[files.length-1]);
//使用 .then() 调用获得结果
await result.then(res => {
previous.push({url: res});
});
}else if(type === "remove") {
previous.splice(index,1);
}
await this.props.dispatch({
type: 'imagePicker/saveImage',
payload: {
files: previous
}
})
}









