react中函数的style如何优雅地写多个?

        this.refs.regular.style.color="#000";
        this.refs.picWord.style.color="#94979c";
        this.refs.interact.style.color="#94979c";

        this.refs.regular.style.borderBottom = "solid 2px #373F42";
        this.refs.picWord.style.borderBottom="none";
        this.refs.interact.style.borderBottom="none";

这段代码如何优雅点写?实在受不了这样一个一个style写下来。。

阅读 9.7k
5 个回答

首先,不要通过refs给child赋值

其次,你根本连官方教程都没看完吧,baidu搜索reactjs第一个就是,看完docs里面的quick start再说

react中尽量避免获取dom 来操作 这种思维是不对的 要基于数据驱动

直接添加类即可

一个案例怎么写style

 render() {
        return (
            <div style={{color : "#000",borderBottom : "solid 2px #373F42" }}></div>
        )
    }

也可以设置变量,但不建议这样,用className属性设置,然后在写类的名称

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题