vue中this.$refs可以拿到,但是里面的属性undefind的问题

1.和vue的生命周期有关,必须要在从mounted开始拿,才能拿得到里面的Dom元素

2.想在element ui 对话框打开后取dom时,应该使用$nextTick,而不是直接使用this.$refs. imgLocal2

        console.log('this.$refs.imgLocal2外面', this.$refs.imgLocal2);
        setTimeout(() => {
          console.log('this.$refs.imgLocal2 setTimeout', this.$refs.imgLocal2);
        }, 500);  // 不推荐
        this.$nextTick(() => {
          console.log('this.$refs.imgLocal2 $nextTick', this.$refs.imgLocal2);
        });
原文地址:https://www.cnblogs.com/xiaoleilei123/p/10906657.html