【问题标题】:React Native: Render HTML in ViewReact Native:在视图中渲染 HTML
【发布时间】:2020-04-04 13:51:06
【问题描述】:

我有一个 React Native 应用程序,它正在从 后端 接收 HTML 文件。这是 HTML 文件的内容:

<html>
  <head>
    <style>
      #wrapper {
        // styling
      }
      .child {
        // styling
      }
      #img {
        // styling
      }
      #desc {
        // styling
      }
    </style>
  </head>

  <body>
    <div id="wrapper">
      <div id="img" class="child"></div>
      <div id="desc" class="child"></div>
    </div>
  </body>

  <script>
    const img = document.getElementById("img");

    img.addEventListener("click", () => {
      // logic
    });
  </script>
</html>

我只想在 react-native 视图中显示这个 HTML 以及它的 style 和 script 标签。

【问题讨论】:

    标签: html react-native


    【解决方案1】:

    您应该为此使用某种预构建的库...

    这是我发现非常有用的一个 => https://github.com/archriss/react-native-render-html

    【讨论】:

    • 您好,我找不到任何可以将脚本与 HTML 一起传递的方法,因为您可以进行 DOM 操作。
    【解决方案2】:

    我使用 React-native-render-html 库来渲染 html,效果很好 用途广泛且非常易于使用,您可以使用它

    https://www.npmjs.com/package/react-native-render-html

    【讨论】:

    • 您好,我找不到任何可以将脚本与 HTML 一起传递的方法,因为您可以进行 DOM 操作。
    猜你喜欢
    • 2015-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多