【发布时间】:2016-10-03 04:17:02
【问题描述】:
Hello comunity :) 我正在 react-native 中开发一个 testapp,并尝试从本地存储位置获取图像。实际我在做什么:我将图像直接链接源提供给 var 并在我的渲染函数中调用此方法。
*react: ^0.14.8 ||*
*react-native: ^0.23.1||*
*npm: 2.15.1 ||*
*node: v4.4.4*
工作:
ImageCall-File (Imagefile.js)
var samplepicture;
setPicture(){
samplepicture= require('./images/picture.png')
}
render() {
this.setPicture;
return(
<Image source=samplepicture/>
);
}
上面的代码 sn-p 在一个以 (Imagefile.js) 命名的类中工作
上面的方法效果很好。
现在我想去哪里> 我想将图像文件保存在一个单独的 js 文件中,该文件的样式类似于 JSON 对象。
不工作:
JS_JSON_File (pictureRef.js)
module.exports = {
"pictureRef":
{
"picture": './images/picture.png'
}}
ImageCall_File (Imagefile.js)
var pictureRef = require('./pictureRef.js');
var samplepicture;
setPicture(){
samplepicture= require(pictureRef.pictureRef.picture);
}
render() {
this.setPicture;
return(
<Image source=samplepicture/>
);
}
调试示例图片: 示例图片 = ./images/picture.png
不确定它是否相关,但因为它是一个字符串,所以它的格式不带''。另外请记住,我需要通过 setPicture() 函数为我的代码设置图像源。
*我调试了两个版本的代码并得到了相同的输出:
- 版本 1:samplepicture = ./images/picture.png
- 版本 2:samplepicture = ./images/picture.png
*
请记住,这是我的第一个问题,我真的希望正确格式化所有内容。我也搜索了许多相关问题,但没有找到任何解决方案
感谢您的帮助。
【问题讨论】:
标签: javascript json image react-native require