【问题标题】:Unable to display a html response inside a div element无法在 div 元素内显示 html 响应
【发布时间】:2021-03-17 00:20:29
【问题描述】:

我习惯于处理 Json,但这个 API 返回一个 HTML 页面,我应该按原样显示它。 问题是我不知道如何 我尝试使用 response.body 查看 html,但什么也没有,而且我不知道如何在 div 元素中显示该页面。

我真的很困惑。有什么想法吗?

    async function getUserData() {
      const url = `${my_Api}/api/userdata`;
      const resp = await fetch(url, {
        method: "GET",
        headers: new Headers({
          "Content-Type": "application/json",
        }),
      });
      return resp;
    }
    getUserData()
        .then((response) => {
              console.log(response)
   });

【问题讨论】:

    标签: html reactjs api


    【解决方案1】:
     <div dangerouslySetInnerHTML={{__html : '/*your html response here*/'}} />
    

    这应该通过附加到此 div 的适当 css 来解决问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-07
      • 1970-01-01
      • 2023-01-24
      • 2018-12-21
      相关资源
      最近更新 更多