如何使用react从具有XML内容的api获取数据

问题描述 投票:0回答:1

无法弄清楚如何从具有XML内容的api获取数据。我尝试使用axios,JSON一切都很清楚。我希望在加载时从api获取数据,并在表单字段中填写相应的值。

reactjs axios
1个回答
0
投票
fetch(URL).then((results) => {
  // results returns XML. Cast this to a string, then create
  // a new DOM object out of it! like this
  results
    .text()
    .then(( str ) => {
      let responseDoc = new DOMParser().parseFromString(str, 'application/xml');
     }
  });

您还可以使用NPM module 来解析XML。

© www.soinside.com 2019 - 2024. All rights reserved.