Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.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 VueJS$refs在:src change之后未定义_Javascript_Vue.js - Fatal编程技术网

Javascript VueJS$refs在:src change之后未定义

Javascript VueJS$refs在:src change之后未定义,javascript,vue.js,Javascript,Vue.js,VueJS 3中的$refs有问题,我有3个绑定到:src的图像,然后我使用一个方法更改:src中的值,但是$refs没有定义。EventListener animationend工作正常,因为控制台错误显示在动画的末尾 这是密码 <img :src="mainImg" class="illustration" @click="switchImg"> <div class="g

VueJS 3中的$refs有问题,我有3个绑定到:src的图像,然后我使用一个方法更改:src中的值,但是$refs没有定义。EventListener animationend工作正常,因为控制台错误显示在动画的末尾

这是密码

<img :src="mainImg" class="illustration" @click="switchImg">
                <div class="glitch_effect" ref="glitchEffect">
                    <img :src="mainImg" class="glitch-one" ref="glitchOne">
                    <img :src="mainImg" class="glitch-two" ref="glitchTwo">
                </div>
使用
()=>{}
而不是
函数(){}
此处
this.$refs.glitchOne.addEventListener(“animationend”,函数(){

export default {
    name: "illustration",
    data() {
        return {
            mainImg: 'https://www.mathieubarco.com/assets/img/sing_for_me.jpg',
        }
    },
    methods: {
        switchImg() {

            this.mainImg = "https://www.mathieubarco.com/assets/img/regina_final.jpg"
            // these $refs are defined and add the class
            this.$refs.glitchOne.classList.add('glitch-active');
            this.$refs.glitchTwo.classList.add('glitch-active');
            this.$refs.glitchEffect.classList.add('glitch-active');

            this.$refs.glitchOne.addEventListener("animationend", function () {
                // these $refs are undifined and don't remove the class
                this.$refs.glitchOne.classList.remove('glitch-active')
                this.$refs.glitchTwo.classList.remove('glitch-active')
                this.$refs.glitchEffect.classList.remove('glitch-active')
            });
        }
    }

}