美文网首页
todoList (react) 简单运用

todoList (react) 简单运用

作者: blank的小粉er | 来源:发表于2020-04-23 18:41 被阅读0次
function Index() {

  const [list, setList] = React.useState(["learn react", "learn Engilish"]);
  const [input, setInput] = React.useState("");
  
  const del=index=>{
    list.splice(index,1)
     setList([...list])
    
  }

  return pug`
      input(onChange=(e) => setInput(e.target.value))
      button(onClick=()=>setList([...list, input]))
        |add 
      ul
        each item,index in list
          li= item 
            button(onClick=()=>del(index))
              |del
  `;
 
}
export default Index;

拆了一个小组件出来

function Ul(props){
  return pug`
          ul
          each item,index in props.list
            li= item 
              button(onClick=()=>props.del(index))
                |del
  
  `
}

function Index() {

  const [list, setList] = React.useState(["learn react", "learn Engilish"]);
  const [input, setInput] = React.useState(""); 
  const del=index=>{
    list.splice(index,1)
     setList([...list])  
  }
  return pug`
      input(onChange=(e) => setInput(e.target.value))
      button(onClick=()=>setList([...list, input]))
        |add 
      Ul(list=list del=del)
  `;
 
}
export default Index;

相关文章

网友评论

      本文标题:todoList (react) 简单运用

      本文链接:https://www.haomeiwen.com/subject/btfzihtx.html