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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM