zoukankan      html  css  js  c++  java
  • react 样式继承 属性传递

    # 样式

    import styled from 'styled-components'

    const Button = styled.button`

      font-size: 20px;

      border: 1px solid red;

      border-radius: 3px;

    `;

    // 一个继承 Button 的新组件, 重载了一部分样式

    const Button2 = styled(Button)`

      color: blue;

      border-color: yellow;

    `;

    export {

      Button,

      Button2

    }

     

    # 显示

    import React, { Component } from 'react'

    import {

      Button,

      Button2

    } from './Styles'

    class App extends Component {

      render() {

        return (

          <div>

            <Button>我是一个按钮1</Button>

            <Button2>我是一个按钮2</Button2>

          </div >

        );

      }

    }

    export default App

     属性传递

    # 样式

    import styled from 'styled-components'

    const Input = styled.input`

      color: ${props => props.inputColor || "blue"};

      border-radius: 3px;

    `;

    export {

      Input

    }

     

    # 显示

    import React, { Component } from 'react'

    import {

      Input

    } from './Styles'

    class App extends Component {

      render() {

        return (

          <div>

            <Input defaultValue="你好" inputColor="red"></Input>

          </div >

        );

      }

    }

    export default App

    右侧打赏一下 代码改变世界一块二块也是爱
  • 相关阅读:
    9.17(day11)
    9.14(day10)
    9.13(day9)
    9.12(day8)
    mysql 的存储过程
    MySQL 子查询与多表联合查询
    MySQL 函数
    MySQL 的查询
    MySQL的约束
    MySQL 表的增删改查操作
  • 原文地址:https://www.cnblogs.com/ht955/p/14922889.html
Copyright © 2011-2022 走看看