feat: 添加随机图片功能
Some checks failed
/ playwright (push) Has been cancelled
/ build-and-deploy-to-vercel (push) Has been cancelled
/ surge (push) Has been cancelled
/ lint-build-and-check (push) Has been cancelled

This commit is contained in:
严浩
2025-04-20 22:09:08 +08:00
parent f4e248a2b1
commit 5f9eeddc77

View File

@ -7,6 +7,14 @@ function getImageUrl(name: string) {
}
const img_modules = import.meta.glob<{ default: string }>('./imgs/*.png', { eager: true });
function getRandom1or2() {
return Math.random() < 0.5 ? '1' : '2';
}
function getRandomImage() {
return getImageUrl(getRandom1or2());
}
</script>
<template>
@ -20,6 +28,11 @@ const img_modules = import.meta.glob<{ default: string }>('./imgs/*.png', { eage
getImageUrl('2'): {{ getImageUrl('2') }}
<img :src="getImageUrl('2')" alt="img_2" />
</div>
<br />
<div b="1px solid pink">
getRandomImage(): {{ getRandomImage() }}
<img :src="getRandomImage()" alt="img_random" />
</div>
</div>
<div class="space-y-4" p="4" b="1px solid pink" mt-4>
<h3>img_modules</h3>