首页 > 解决方案 > 如何使用 vuejs 服务器端读取 xml 文件内容?

问题描述

我需要读取存储在服务器端特定路径中的 xml 文件。我正在使用 VueJS,我不能使用 JQUERY ......你能帮我一些想法或建议吗?

案例:1.文件将存储在/static/label/custom-label.xml 2.我需要读取服务器端的这个文件并加载内容。3.我将使用一个const加载的内容。

标签: javascriptxmlvue.jsfilereader

解决方案


不确定您使用的是什么后端,但它被标记为 JS,所以我假设使用 Node/Express。如我错了请纠正我。

使用 express 中间件来定义您的路径。如果您将资产存储在服务器上以供公众使用,请将它们存储在您的/public/文件夹中。

app.use('/static', express.static('public'));
app.use(express.static('files'));

使用/static/路由获取静态资源

http://localhost:3000/static/foobar.jpg

https://expressjs.com/en/starter/static-files.html

这篇 SO 帖子可能会有所帮助:Read remote file with node.js (http.get)


推荐阅读