1、domtoimage插件自行下载,在页面中引入domtoimgge插件
2、直接下载图片
var exportOptions = { filter: function(element) { return true; } }; var node = document.getElementById('printDiv'); domtoimage.toBlob(node, exportOptions) .then(function(dataURL) { var name="专题图.png"; window.saveAs(dataURL,name); });
3、获取base64位码
var exportOptions = { filter: function(element) { return true; } };
var node = document.getElementById('printDiv');
domtoimage.toBlob(node, exportOptions)
.then(function(dataURL) {
me.blobToDataUR(dataURL,function(args){
var parts = args.split(';base64,');
data=parts[1];
if(callback)
callback(data);
})
});
blobToDataUR:function (blob, callback) { var a = new FileReader(); a.onload = function (e) { callback(e.target.result); } a.readAsDataURL(blob); },