欢迎来到蕾蕾的博客

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);
        });
posted @ 2019-05-22 16:23  蕾蕾是个程序员  阅读(5151)  评论(0编辑  收藏  举报