Javascript 使用transiontioend事件时返回未定义的引用
我在transitionend事件后从状态获取数组,但它返回未定义 这是我的代码,我在单击事件中使用此函数,但它返回this.slider.current 未定义Javascript 使用transiontioend事件时返回未定义的引用,javascript,reactjs,Javascript,Reactjs,我在transitionend事件后从状态获取数组,但它返回未定义 这是我的代码,我在单击事件中使用此函数,但它返回this.slider.current 未定义 this.state = { slides: [{ src: slide1, name: "Livingroom1", id: Math.random().toString(36).subst
this.state = {
slides: [{
src: slide1,
name: "Livingroom1",
id: Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
},
{
src: slide2,
name: "Livingroom2",
id: Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
},
{
src: slide3,
name: "Livingroom3",
id: Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
},
{
src: slide1,
name: "Livingroom4",
id: Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
},
{
src: slide2,
name: "Livingroom2",
id: Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
},
{
src: slide3,
name: "Livingroom3",
id: Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
}
]
}
它以未定义的状态返回我的幻灯片,而不是
函数(e){
尝试此(e)=>{
componentDidMount() {
this.slider.current.addEventListener('transitionend', function (e) {
console.log('transitionend', e.propertyName);
if (e.propertyName === 'transform') {
if (this.el === 1) {
var pop = [...this.state.slides];
pop.pop();
this.setState({
slides: [this.state.slides[5], ...pop]
});
} else {
var shift = [...this.state.slides];
shift.shift();
this.setState({
slides: [...shift, this.state.slides[0]]
});
}
console.log(this.slider.current);
this.slider.current.style.transform = 'translate(0)';
setTimeout(() => {
this.slider.current.style.transition = 'all 0.3s';
})
}
});
}