获取空值不是一个对象(正在评估“ scratchImagePath.uri”),尽管我正在传递值?

问题描述 投票:0回答:1
<ScratchImageView 
                brushSize = {10}
                threshold = {10}
                style={{height: 300, width: 300}}
                onRevealPercentChanged={this.onRevealPercentChanged}
                onRevealed={this.onRrevealPercent=50}
                resizeMode= "cover"
                strokeWidth={20}
                imageScratched={{uri: './scratchReward.jpg'}}
                imagePattern={{uri: './scratchTopLayer.jpg'}}
            />

为什么我传递null却不是对象异常,尽管传递值?

react-native react-native-android react-native-ios
1个回答
0
投票

您可以尝试使用require,例如

require('./path/to/image.png')

所以您的组件代码=将是

        <ScratchImageView 
                brushSize = {10}
                threshold = {10}
                style={{height: 300, width: 300}}
                onRevealPercentChanged={this.onRevealPercentChanged}
                onRevealed={this.onRrevealPercent=50}
                resizeMode= "cover"
                strokeWidth={20}
                imageScratched={uri: require('./scratchReward.jpg')}
                imagePattern={uri: require('./scratchTopLayer.jpg')}
            />

您可以在此处使用相对路径。

© www.soinside.com 2019 - 2024. All rights reserved.