我正在使用最新的 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/