传统的方法获取dom元素操作dom,通常是获取类名,id,属性等来获取到dom,但在vue中获取组件dom的话会有问题,请看下面代码:
控制台打印出来的结果如下,你会发现正常标签可以正常显示,但是组件就不行,它将你的组件转化成一个标签形式的了,显然这不是我们想要的效果
所以vue中给了我们更好的选择,通过ref 来获取dom元素:
这时我们控制台才可以打印出我们真正想要的数据,会发现组件里面的方法和属性都可以获取得到