根據圖檔url位址儲存至本地
downloadIamge(imgsrc, name) {//下載下傳圖檔位址和圖檔名
let image = new Image();
// 解決跨域 Canvas 污染問題
image.setAttribute("crossOrigin", "anonymous");
image.onload = function() {
let canvas = document.createElement("canvas");
canvas.width = image.width;
canvas.height = image.height;
let context = canvas.getContext("2d");
context.drawImage(image, 0, 0, image.width, image.height);
let url = canvas.toDataURL("image/png"); //得到圖檔的base64編碼資料
let a = document.createElement("a"); // 生成一個a元素
let event = new MouseEvent("click"); // 建立一個單擊事件
a.download = name || "photo"; // 設定圖檔名稱
a.href = url; // 将生成的URL設定為a.href屬性
a.dispatchEvent(event); // 觸發a的單擊事件
};
image.src = imgsrc;
},