【发布时间】:2019-07-06 10:04:38
【问题描述】:
我无法让 baseUrl 参数在 react-native-webview 中工作。我的项目结构如下:
root
---> _tests _
---> android
-------> web
---> ios
---> node_modules
---> src
-------> components
------------> web
------------> MyComponent.js
---> web
如图所示,我已经插入了3次web文件夹(实际上只需要一次,这只是为了测试)。每个“web”文件夹都包含 ponies.jpg。然而,React Native 什么也没得到。我只得到了 4 张带有 alt(即“小马”)显示的破损图像。我也尝试过使用 baseUrl: 'web/' 无济于事。这是 MyComponent.js 中的代码:
import React from 'react';
import {View, Text, StyleSheet, Image} from "react-native";
import {WebView} from "react-native-webview";
var html = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<img src="ponies.jpg" alt="Ponies" height="42" width="42">
<img src="ponies.jpeg" alt="Ponies" height="42" width="42">
<img src="./ponies.jpg" alt="Ponies" height="42" width="42">
<img src="./ponies.jpeg" alt="Ponies" height="42" width="42">
</body>
</html>
`;
export default class MyComponent extends React.Component {
render() {
return (
<View style = {styles.container}>
<WebView
style = {styles.webview}
source = {{html: html, baseUrl: 'web/'}}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
height: 350,
width: 350
},
webview: {
height: 350,
}
})
谢谢!
【问题讨论】:
标签: reactjs react-native android-webview native