zoukankan      html  css  js  c++  java
  • React JSX

    使用JSX代替常规Javascript

    使用JSX自定义属性 data-自定义属性名

    ReactDOM.render(
      <p data-selfattr='somevalue'>JSX</p1>,
      document.getElementById('example')   
    )

    独立文件

    hello.js
    ReactDOM.render(
      <div>hello</div>,
      document.getElementById('example')
    )
    //在要使用的文件里引入
    <div id="example"></div>
    <script src="hello.js" type="text/babel"></script>

    表达式写在{}中,JSX不能使用if else 可以用三元运算符

    样式

    var myStyle={
      fontSize:100,//自动加上px
      color:'#ff0000'
    }
    ReactDOM.render(
      <h1 style={myStyle}>hello</h1>,
      document.getElementById('example')
    )
    ReactDOM.render(
        <h1 style = {{fontSize:12}}>菜鸟教程</h1>,
        document.getElementById('example')
    );

    数组

    //JSX允许在模板中插入数组,数组会自动展开
    var arr=[
      <h1>hello world</h1>,
      <h1>hello JSX</h1>
    ];
    ReactDOM.render(
     <div>{arr}</div>,
      document.getElementById('example')
    )
  • 相关阅读:
    python 笔记8
    python笔记6
    python笔记5
    python笔记4
    python笔记3
    python课程2
    cobbler 坑爹指南
    hadoop filesystem 删除文件 复制文件 重命名文件
    hadoop 文件 复制 移动 FileUtil.copy
    soinn
  • 原文地址:https://www.cnblogs.com/shui1993/p/9958569.html
Copyright © 2011-2022 走看看