Skip to content

Commit

Permalink
fix: filename of downloaded image
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Jan 26, 2024
1 parent fa6b014 commit 824f6c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/ResultItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function copyTitle() {
</Badge>
</span>
<ul>
<TokutenItem v-for="item in data.items" :data="item" />
<TokutenItem v-for="(item, i) in data.items" :title="data.title" :index="i" :data="item" />
</ul>
</li>
</template>
5 changes: 3 additions & 2 deletions components/TokutenItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { toast } from 'vue-sonner';
import { Download, Copy, ClipboardCopy } from 'lucide-vue-next';
const props = defineProps<{
title: string;
index: number;
data: DetailItem;
}>();
const img = useImage();
async function downloadImage() {
try {
const imageURL = new URL(props.data.image);
const image = img(props.data.image);
console.log(`下载图片:`, image);
const blob = await $fetch<Blob>(image, { responseType: 'blob' });
Expand All @@ -21,7 +22,7 @@ async function downloadImage() {
// 创建 a 标签
const a = document.createElement('a');
a.href = url;
a.download = imageURL.pathname.split('/').at(-1) || 'downloaded_image';
a.download = `${props.title}_${props.index}`;
a.click();
// 清理
Expand Down

0 comments on commit 824f6c5

Please sign in to comment.