如何使用Svelte将所有文件获取目录中的所有文件?
我想在文件夹中显示所有图像,例如:
<script>
let list = /*array of all files in a folder*/;
</script>
{#each list as l}
<img src={(path_of_l)} alt=""/>
{/each}
如何获得该元素的“列表”及其路径?
I want to show all images in a folder, like:
<script>
let list = /*array of all files in a folder*/;
</script>
{#each list as l}
<img src={(path_of_l)} alt=""/>
{/each}
How can I get that 'list' and paths of its elements?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当图像在您的项目文件夹中并且使用Vite(或Sveltekit)时,您可以使用 Glob Import 功能:
When the images are inside your project folder and you're using Vite (or SvelteKit) you can use the Glob Import feature: