Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 是否将图像设置为相对于屏幕大小的大小?_Javascript_Reactjs_React Native - Fatal编程技术网

Javascript 是否将图像设置为相对于屏幕大小的大小?

Javascript 是否将图像设置为相对于屏幕大小的大小?,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我对本地语言和Javascript非常陌生,一直在努力学习。我试图将图像的宽度设置为屏幕大小除以10。我使用屏幕宽度和高度设置了构造函数和状态,但无法使用状态设置图像的宽度或高度 constructor(props) { super(props); const { width, height } = Dimensions.get("window") this.state = { width, height } } 如果我这样做

我对本地语言和Javascript非常陌生,一直在努力学习。我试图将图像的宽度设置为屏幕大小除以10。我使用屏幕宽度和高度设置了构造函数和状态,但无法使用状态设置图像的宽度或高度

constructor(props) {
     super(props);
     const { width, height } = Dimensions.get("window")
     this.state = {
       width,
       height
     }
}
如果我这样做

<Image source={require('./my-icon.png')} style={{width: {this.state.width}, height: 40}}/>


它给我一个错误,说“this”是保留字。

我修复了它。我想我犯了一个愚蠢的错误。我拆下了支架,它成功了

<Image source={require('./my-icon.png')} style={{width: this.state.width/10, height: 40}}/>