feat: 添加随机图片功能
This commit is contained in:
@ -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>
|
||||
|
Reference in New Issue
Block a user