需求:图片列表页,点击图片,呈现图片原始放大尺寸;
方法:增加点击事件;
<a>
<img
src="data:image/jpeg;base64,${item.baseimg}"
onclick="imgTarget(this)"
alt="${item.adress}"
onerror="this.src='/img/face/dialog.gif';this.οnerrοr=null"
/>
<a/>
备注:上边 "data:image/jpeg;base64,"是字符串,拼接出base64的完整图片格式,
${item.baseimg} 是后台传过来的数据;
function imgTarget(e){
let src = e.getAttribute('src'); //base64格式的地址
const img = new Image();
img.src = src;
const newWin = window.open("", "_blank");
newWin.document.write(img.outerHTML);
newWin.document.title = "报警图";
newWin.document.close();
}