export default class Lunbo extends React.Component<any,any>{
constructor(props:any){
super(props);
this.state = {
locations: [“left100”, “left100”, “left100”, “left100”, “left100”],
index:0,
timer:null,
locationss: [“left0”, “left100”, “left100”, “left100”, “left100”]
}
}
componentDidMount() {
this.l()
}
componentWillUnmount(){
clearInterval(this.state.timer)
}
l() {
const timer = setInterval(() => {
let {index, locations} = this.state
let _data = locations
if(index >= _data.length - 1) {
this.setState({index: 0})
}else{
this.setState({index: index + 1})
}
console.log(this.state.index)
_data[this.state.index] = "left0"
if(this.state.index + 1 > _data.length - 1){
_data[0] = "left100"
}else{