如果我刚开始
require('../img/dest.png')
图像是有效的,但是当我试图使用
它会显示错误
calls to require expect exactly 1 string literal argument but this was found: require(""+item.img+"").(null)
有人知道我的美元变量是怎么回事吗?
提前谢谢。
render() {
const items = [
{ name: 'Name', code: '#1abc9c', url: 'yahoo.com.tw', img: '../img/dest.png' }
];
return (
<GridView
itemDimension={130}
items={items}
style={styles.gridView}
renderItem={item => {
console.log(`'${item.img}'`);
return (
<TouchableOpacity onPress={() => this.showLinkAlert(item.name, item.url)}>
<ImageBackground source={require(`'${item.img}'`)} style={[styles.itemContainer, { backgroundColor: '#bdc3c7' }]}>
<Text style={styles.itemName}>{item.name}</Text>
</ImageBackground>
</TouchableOpacity>
);
}}
/>
);
}
}