本文共 1481 字,大约阅读时间需要 4 分钟。
import React, { Component } from 'react'export default class App extends Component { state = { datalist:["aaa","bbb","ccc","ddddd"] } mytext = React.createRef() render() { // console.log(this) return () } handleClickAdd() { console.log("click", this.mytext.current.value) // this.state.datalist.push(this.mytext.current.value) // this.forceUpdate() this.setState({ datalist:[...this.state.datalist,this.mytext.current.value] }) this.mytext.current.value = "" //ref 引用清空 } handleDel(index){ // this.state.datalist.splice console.log("del",index) // this.state.datalist.splice(index,1) var newlist = [...this.state.datalist] newlist.splice(index,1) this.setState({ datalist:newlist }) }}var list= ["aaa","bbb","ccc"]var newlist = list.map(item=>`{ this.state.datalist.map((item,index)=>
- { item}
) }
转载地址:http://nqyrf.baihongyu.com/