如何在NUXTJ中的静态文件夹下获取所有文件名?

发布于 2025-02-05 07:35:30 字数 92 浏览 2 评论 0原文

我在nuxtjs有一个前端。我想列出存储在静态文件夹下的所有PDF,并在浏览器中以单独的窗口打开这些文档,并创建一个动态链接。 因此,我想获取特定文件夹的所有文件的列表。

I have a frontend in NuxtJs. I want to list out all the PDFS stored under the static folder and make a dynamic link to open those documents in the browser as a separate window.
So I want to get the list of all the files of specific folder.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凡尘雨 2025-02-12 07:35:31

nuxt.config.js使用FS模块作为默认加载程序。
我们可以将此代码段添加到nuxt.config.js文件中,并将响应存储到Env变量中,以便可以在任何地方使用。

const fs = require('fs')
// To read Static Files
const files = fs.readdirSync('./static/pdfs')
process.env.STATIC_REFERRAL_DOCS = files

Nuxt.config.js uses fs module as default loader.
we can add this snippet of code to the Nuxt.config.js file and store the response to the env variable so that it can be used anywhere.

const fs = require('fs')
// To read Static Files
const files = fs.readdirSync('./static/pdfs')
process.env.STATIC_REFERRAL_DOCS = files
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文