Image 当图像(来自react native)抛出onError时呈现文本组件
在图像加载失败时,我想通过组件的onError函数呈现文本组件 我尝试过使用这个,但失败了!(尽管OneError正在被触发)Image 当图像(来自react native)抛出onError时呈现文本组件,image,react-native,Image,React Native,在图像加载失败时,我想通过组件的onError函数呈现文本组件 我尝试过使用这个,但失败了!(尽管OneError正在被触发) View style={styles.imgView}> { 返回( {value} ); }} /> 这不对,请执行以下操作: constructor() { this.state = { isError: false } } render() { return ( <
View style={styles.imgView}>
{
返回(
{value}
);
}}
/>
这不对,请执行以下操作:
constructor() {
this.state = {
isError: false
}
}
render() {
return (
<View style={styles.imgView}>
{this.state.isError? (
<Text size="S" white>
{value}
</Text>
): <Image
source={{
uri: `https://google.com/icon/tags/${value}.png`,
}}
style={styles.imageStyle}
onError={this.imageLoadError}
/>}
</View>
)
}
imageLoadError = () => {
this.setState({
isError: true
})
}
constructor(){
此.state={
伊瑟罗:错
}
}
render(){
返回(
{this.state.isError(
{value}
): }
)
}
imageLoadError=()=>{
这是我的国家({
伊瑟罗:是的
})
}
constructor() {
this.state = {
isError: false
}
}
render() {
return (
<View style={styles.imgView}>
{this.state.isError? (
<Text size="S" white>
{value}
</Text>
): <Image
source={{
uri: `https://google.com/icon/tags/${value}.png`,
}}
style={styles.imageStyle}
onError={this.imageLoadError}
/>}
</View>
)
}
imageLoadError = () => {
this.setState({
isError: true
})
}