【问题标题】:warning: failed prop type: invalid prop 'backgroundcolor' supplied to view:警告:道具类型失败:提供给视图的道具“背景颜色”无效:
【发布时间】:2018-07-21 18:56:57
【问题描述】:

我有一个十六进制颜色,通过这个文件中的道具接收,十六进制代码是'#BE2625'。在它正确显示但是当我将相同的应用于 backgroundColor 时,颜色不会显示,而是会向我发出警告

警告:道具类型失败:提供给视图的道具“背景颜色”无效:“#BE2625”有效颜色格式为.......

import React from 'react';
import {StyleSheet, View, Text} from 'react-native'


export default class Color extends React.Component {

  
  render() {

    const {Color} = this.props;
    
    return (
   <View style={[styles.bodyColor, {backgroundColor: `'${Color}'` }]}>
    <Text style={styles.hex}>  {Color} </Text>
    </View>
    );
  }
}


const styles = StyleSheet.create({
    bodyColor :{
        height:50,
        margin:10,
       
        
    },

    hex :{
        textAlign:'center',
        fontSize: 22,
        padding:10
    }
})

【问题讨论】:

    标签: javascript react-native


    【解决方案1】:

    您的颜色字​​符串中有额外的' 字符:

    <View style={[styles.bodyColor, {backgroundColor: `'${Color}'` }]}>
                                                       ^
                                                       this one here
    

    您应该删除它们并使用:

    <View style={[styles.bodyColor, {backgroundColor: `${Color}` }]}>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-22
      • 1970-01-01
      • 2018-04-23
      • 2021-01-18
      • 2017-12-26
      相关资源
      最近更新 更多