亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    react怎么寫style

    react寫style的方法:1、使用內(nèi)聯(lián)式;2、使用className方法;3、使用classnames動態(tài)修改樣式;4、使用【styled-components】插件寫標簽樣式。

    react怎么寫style

    本教程操作環(huán)境:windows7系統(tǒng)、React17版,該方法適用于所有品牌電腦。

    react寫style的方法:

    1、內(nèi)聯(lián)式

    import React, { Fragment } from "react"; class Style extends React.Component {   constructor(props) {     super(props);   }   render() {       const txtColor = {           color: '#F00'       }     return (      <Fragment>          <h1 style={txtColor}></h1>      </Fragment>     );   } } export default Style;

    這種寫法不推薦使用,樣式多了之后,會導(dǎo)致代碼比較亂!

    2、使用className

    import React, { Fragment } from "react"; import "./../../style.css"; class Style extends React.Component {   constructor(props) {     super(props);   }   render() {     return (      <Fragment>          <h1 className="textColor"></h1>      </Fragment>     );   } } export default Style;

    新建一個.css文件,將文件引進來,標簽中使用className=“textColor”,就可以使用引入.css文件中類為’textColor’的樣式了.一般的項目用這個方式就可以了.

    3、使用classnames動態(tài)修改樣式

    import React, { Fragment } from "react"; import classNames from 'classnames' class Style extends React.Component {   constructor(props) {     super(props);   }   render() {     return (      <Fragment>          <h1 className={classNames('textColor', {'textContent': false} ,{'textTitle': true})}></h1>      </Fragment>     );   } } export default Style;

    這種動態(tài)修改樣式的方式,需要安裝插件classnames.上面的代碼中,h1標簽的類有textColor和textTitle.項目中一般也會使用.

    4、使用styled-components插件寫標簽樣式

    import React, { Fragment } from 'react' import styled from 'styled-components' const Title = styled.h1`   color: #f00; ` class Style extends React.Component {   constructor(props) {     super(props)   }   render() {     return (       <Fragment>         <Title>復(fù)習style</Title>       </Fragment>     )   } } export default Style

    使用styled-components給標簽寫樣式,首先需要安裝該插件.上面的代碼是定義一個Title,通過styled給h1標簽設(shè)置樣式,然后在組件中使用的Title就相當于寫過樣式的h1標簽.這種方式在大項目中比較常見.

    相關(guān)免費學習推薦:javascript(視頻)

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號