或亲属
在我的phonegap构建中,我很难让我的图像工作。
我读到绝对路径可能不起作用,所以我尝试了绝对路径和相对路径,仍然没有运气。
我包括这样的图片:
<Col key={1} xs={3}>
<Image src='/tire_selected.png' responsive />
</Col>
或亲属
<Col key={1} xs={3}>
<Image src='tire_selected.png' responsive />
</Col>
等于
<img class="img-responsive" src="tire_deselected.png" data-reactid=".0.0.1.0.0.0.0.1.1.0.0.$4.0">
Col & Image是使用引导-反应的引导辅助组件。这一切在网络视图中都很好,但在使用phonegap构建时就不行了。但是,应该已经编译了源代码,并且在这两种情况下都没有错误。
以下是我的config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.app.exampleapp" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<name>App</name>
<description>
App
</description>
<author email="support@example.com" href="http://www.example.com">
Author
</author>
<content src="index.html" />
<preference name="permissions" value="none" />
<preference name="orientation" value="default" />
<preference name="target-device" value="universal" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
<preference name="prerendered-icon" value="true" />
<preference name="stay-in-webview" value="false" />
<preference name="ios-statusbarstyle" value="black-opaque" />
<preference name="detect-data-types" value="true" />
<preference name="exit-on-suspend" value="false" />
<preference name="show-splash-screen-spinner" value="true" />
<preference name="auto-hide-splash-screen" value="true" />
<preference name="disable-cursor" value="false" />
<preference name="android-minSdkVersion" value="14" />
<preference name="android-installLocation" value="auto" />
<gap:plugin name="org.apache.cordova.geolocation" />
<icon src="icon.png" />
<access origin="*" />
<plugin name="cordova-plugin-whitelist" version="1" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
</widget>
Git储存库:
app.js
vendor.js
config.xml
favicon.ico
humans.txt
index.html
robots.txt
tire_deselected.png
tire_selected.png
不过,Icon.png工作得很好。我不知道是什么导致其他图像不工作。任何帮助都将不胜感激!
编辑
我尝试过设置内容安全策略,如果这是我无法设置images并通过javascript显示图像的问题。
<meta http-equiv="Content-Security-Policy" content="
default-src http://10.3.10.104/ 'self' * 'unsafe-inline';
style-src http://10.3.10.104/ 'self' * 'unsafe-inline';
img-src http://10.3.10.104/ 'self' * 'unsafe-inline';
script-src http://10.3.10.104/ 'self' * 'unsafe-inline';">
但还是没有运气
file:///tire_deselected.png net::ERR_FILE_NOT_FOUND
文件就在那里,因为当将img-元素插入到index.html中时,就会显示它。
我甚至尝试通过运行developer tools的源文件夹中显示的路径访问它。
file:///data/user/0/com.oas.exampleapp/files/downloads/app_dir/tire_deselected.png
也不起作用,我开始认为phonegap被打破了,至少在结合react时效果很差。
发布于 2016-04-05 04:24:35
编译后,build.phonegap.com将源文件放入"www“目录。
您可以使用以下路径"/android_asset/www/“访问本地映像文件
<image src='/android_asset/www/tire_selected.png' responsive />
如果您的图像被放置在根目录中的子目录中,那么您可以使用以下内容:
<image src='/android_asset/www/sub-direcctory/tire_selected.png' responsive />
注意:如果存在包含本地图像文件的任何内容,则将“子目录”替换为您自己的。
发布于 2016-10-07 10:46:19
我向index.html添加了一个img标记,并将src属性设置为"images/logo.png“,并且它没有问题地加载。
...
<body>
<div id="root"></div>
<img id="footer-logo" src="images/logo.png" style="background-color: black; width: 200px;" />
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script src="js/vendor.bundle.js"></script>
<script src="js/app.bundle.js?v=2"></script>
</body>
</html>
我有一个带有img标记和相同src值“映像/logo.png”的react组件
...
<div style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 0px; padding-top: 0px; letter-spacing: 0px; font-size: 24px; font-weight: 400; color: rgb(48, 48, 48); height: 64px; line-height: 64px; flex: 1 1 0px; text-align: center;">
<img id="header-logo" src="images/logo.png" style="width: 105px; margin-top: 16px;">
</div>
...
react组件中的img不加载;404。然而,这等同于真理。
document.getElementById('footer-logo').src === document.getElementById('header-logo').src
为什么其中一个图像加载而另一个图像没有加载?它是否与动态加载到DOM中的react组件或react的虚拟DOM有关?
src属性等同于file:///images/logo.png
。如果我像这样在#header-徽标上设置src属性,它将加载:
document.getElementById('header-logo').src = cordova.file.applicationDirectory + "www/images/logo.png"
希望这提供了更多的信息,这种非常奇怪的行为。
发布于 2019-04-16 10:30:33
希望这能有所帮助。所以我也有这个问题。
我所做的就是创建另一个文件夹/images/
(复制),并且仍然使用我通过/static/components/images
文件夹导入的图像。您可以通过添加用于暂存或活动的条件来更进一步。
答案就在这里:
import Logo from '../images/logo.png';
<img src={`./${Logo}`} alt="Logo" />
完整的例子。:
import React, { Component } from 'react';
import Logo from '../images/logo.png';
class Header extends Component {
render() {
return(
<div className="logo mt-3">
<img src={`./${Logo}`} alt="Logo" />
</div>
);
}
}
export default Header;
从这篇文章中得到了这个想法.:没有显示在PhoneGap构建应用程序中的图像
https://stackoverflow.com/questions/36284097
复制相似问题