Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用transiontioend事件时返回未定义的引用_Javascript_Reactjs - Fatal编程技术网

Javascript 使用transiontioend事件时返回未定义的引用

Javascript 使用transiontioend事件时返回未定义的引用,javascript,reactjs,Javascript,Reactjs,我在transitionend事件后从状态获取数组,但它返回未定义 这是我的代码,我在单击事件中使用此函数,但它返回this.slider.current 未定义 this.state = { slides: [{ src: slide1, name: "Livingroom1", id: Math.random().toString(36).subst

我在transitionend事件后从状态获取数组,但它返回未定义 这是我的代码,我在单击事件中使用此函数,但它返回this.slider.current 未定义

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';
            })
        }

    });

      }