vue this.$refs 获取的值为undefined?

首先你要知道 this.$refs 是干嘛的 ?

直接上图

 

 

也就是对于 dom进行操作 

 

当你再created中使用 this.$refs时 dom没有加载成功 所以为undefined

所以你要是想获取

1、要么写在mounted中 dom已经加载完成

2、使用this.$nextTick(function(){})

 

 

posted @ 2020-04-23 11:29  有梦想的咸鱼7  阅读(30409)  评论(2编辑  收藏  举报