React 使用refs动态设置样式

最近用React + Redux做前端页面需要用到动态实现css, 示例代码如下仅供参考:

import React, {Component} from 'react';

export default class extends Component {
    constructor (props) {
        super(props)
    }

    changeLang(currLang = 0) {
        this.refs.langBtnList.style.minWidth = '110px';
        this.refs.langBtnList.style.display == 'block' || this.refs.langBtnList.style.display == true ? this.refs.langBtnList.style.display = 'none' : this.refs.langBtnList.style.display = 'block';
        
        if(currLang > 0 ){
            console.log('currLang:', currLang)
        }
    }

    render () {
        return (
            
  • ) } }

    结束语

    对你有帮助或喜欢的话,欢迎关注、打赏,收藏,谢谢!

    你可能感兴趣的:(React 使用refs动态设置样式)