<template>
<div>
<img :src="url" alt="" @click="downLoad">
</div>
</template>
<script>
export default {
data() {
return {
url: '图片地址'
}
},
methods: {
downLoad() {
fetch(this.url)
.then(response => response.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = '下载文件名称'
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
})
.catch(error => console.error('Error downloading file:', error));
}
}
}
</script>
<style>
img{
width: 500px;
height: 500px;
}
</style>
01-07
06-14
2162
09-19
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交