【问题标题】:How to read xml file content with vuejs Server side?如何使用 vuejs 服务器端读取 xml 文件内容?
【发布时间】:2019-02-26 20:54:27
【问题描述】:

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

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

【问题讨论】:

  • 好的,我找到了一种快速解决问题的方法getLabelXml() { let result = null; const xmlhttp = new XMLHttpRequest(); xmlhttp.open('GET', '/label/paciente.label', false); xmlhttp.send(); if (xmlhttp.status === 200) { result = xmlhttp.responseText; } return result; }

标签: javascript xml vue.js filereader


【解决方案1】:

不确定你使用的是什么后端,但它被标记为 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)

【讨论】:

  • 谢谢彼得...我找到了另一种方法,但您的解决方案很有帮助。
  • 啊..我的解决方案是getLabelXml() { let result = null; const xmlhttp = new XMLHttpRequest(); xmlhttp.open('GET', '/label/paciente.label', false); xmlhttp.send(); if (xmlhttp.status === 200) { /result = xmlhttp.responseText; } return result; }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-25
  • 1970-01-01
  • 1970-01-01
  • 2023-04-04
相关资源
最近更新 更多