react学习day1

1.创建项目

npx create-react-app react-basic

2.jsx的变量渲染方式

import React from 'react';
import './App.css';
const count=12
function test(){
  return 33
}
function App() {
  return (
    <div>
      {/* 变量 */}
      {count}
      {/* 字符串 */}
      {'this is a message'}
      {/* 方法 */}
      {test()}
      {new Date().getDate()}
      {/* js对象 */}
      <div style={{color:'red'}}>test</div>
    </div>
  );
}
export default App;

3.列表渲染

import React from 'react';
import './App.css';
const list=[
  {id:11,name:'vue'},
  {id:12,name:'react'},
  {id:13,name:'angular'},
]
function App() {
  return (
    <div>
      {/* 列表渲染 */}
      <ul>{list.map(v=><li key={v.id}>{v.name}</li>)}</ul>
    </div>
  );
}
export default App;

4.条件渲染

import React from 'react';
import './App.css';
const isLogin=true
const article=1
function getArticle(){
  if(article==1){
    return <div>我是无图文章</div>
  }else if(article==2){
    return <div>我是有图文章</div>
  }
}
function App() {
  return (
    <div>
      {isLogin&&<span>test11</span>}
      {isLogin?<span>login</span>:<span>nologin</span>}
      {getArticle()}
    </div>
  );
}
export default App;

5.事件绑定

import React from 'react';
function App() {
  const handlerclick=(e)=>{
    // alert('click')
    console.log(e)
  }
  const handlerClick1=(name,e)=>{
    console.log('button click',name,e)
  }
  return (
    <div>
      <button id='test' onClick={(e)=>handlerClick1('jack',e)}>Click</button>
    </div>
  );
}
export default App;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值