2016-09-27 2 views
0

이 사용자의 상자를 클릭하면 내 코드 로직, 내가 drag-and-resize-box-text clicked 를 반환합니다 true
getCssStyle()에 상태 active을 설정합니다입니다 후 배경 이미지 (T는)새로운 CSS 스타일을 렌더링하지 않았다 반작용

을 사라
class Box extends Component { 
    constructor(props) { 
    super(props); 
    this.state = { 
     active: false, 
    } 
    } 

    // decide which style to be used 
    getCssStyle = (type) => { 
    switch (type) { 
     case 'text': 
     if (this.state.active) { 
      console.log("AAA") 
      return 'drag-and-resize-box-text clicked' 
     } else { 
      console.log("BBB") 
      return 'drag-and-resize-box-text'; 
     } 
     // break; 
     default: 
     return ''; 
    } 
    } 

    onClick =() => { 
    this.setState({active: true}); 
    } 

    render() { 
    return ( 
      <div className={this.getCssStyle(boxType)} > 
      {this.boxFillContent()} 
      </div> 
     </div> 
    ); 
    } 
} 

dev 도구는 배경 이미지가 삭제되었음을 보여 주지만 페이지에는 여전히 이미지가 표시됩니다.
무엇이 문제입니까?

enter image description here

CSS

.drag-and-resize-box-text{ 
    border: dashed 3px LightSeaGreen; 
    background: url(../images/bottom/text_normal.png) no-repeat; 
    background-position:center; 
    width: inherit; 
    height: inherit; 
} 

.drag-and-resize-box-text.clicked{ 
    border: dashed 3px LightSeaGreen; 
    /*background: url(../images/bottom/text_normal.png) no-repeat;*/ 
    background-position:center; 
    width: inherit; 
    height: inherit; 
} 

답변

0

배경이 없어야합니다 .drag 및 사이즈 변경 - 박스 text.clicked : 없음.

또한 코드는

<div className={this.state.active ? 'drag-and-resize-box-text clicked' : 'drag-and-resize-box-text'} > 
    {this.boxFillContent()} 
</div> 
+0

감사합니다 사용하여 훨씬 더 간단 할 수있다! 'background : none'이 잘 작동하고 코드가 훨씬 좋다! – user2492364

관련 문제