android - 通过 React Native 和 Expo 在 WebView 中使用本地文件中的 CSS

标签 android ios react-native exponent expo

我正在使用最新的 Expo SDK。我使用非分离项目。 我需要从 WebView 中的本地文件加载 css,该文件从字符串加载 html,如下所示:

<WebView source={{ baseUrl: './', html: this.fullPost }} />

其中 this.fullPost 看起来像这样

this.fullPost = `
  <html>
    <head>
      <link rel="stylesheet" href="css/style.css" />
    </head>
    <body>some html that uses style.css</body>
  </html>`;

那么我应该将 style.css 文件放在哪里以及应该指定什么作为 baseUrl ? 世博会该如何应对?

谢谢。

最佳答案

最简单的方法是将 CSS 代码包装到 JavaScript 文件中:

样式.js:

const css = `
<style>
// copy your css file's content here
</style>
`;
export default css;

然后只需从 './style'; 导入样式;,您就可以简单地将 style 连接到 this.fullPost

关于android - 通过 React Native 和 Expo 在 WebView 中使用本地文件中的 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45743127/

相关文章:

react-native - 使用 ReactNative + Redux-persist V 5.10 时出错

安卓工作室错误 :Execution failed for task ':app:compileDebugJavaWithJavac'

java - 如何在用户可见时加载一个 fragment 数据并在加载一次后保留数据

android - 如何在没有任何用户交互的情况下返回到之前的 Activity

iOS;使用 ZXing 2.0,无法使用 Xcode 4.2 链接到 libZXingWidget.a

ios - Firebase 身份验证 : Phone number authentication in Swift

android - 如何在FlatList React Native中实现复选框

android - 如何在 react native 的通知中设置图像?

android - 从文本文件中获取 int 并将其设置为变量

ios - Xcode Swift 2 变量声明(实例成员不能用于类型 View Controller )