1.加在普通元素上,来获取当前元素节点。(通过this.$refs.list)
<div class="list" ref="list"></div>
2.ref 加在子组件上,通过this.refs.topComponent.+子组件中的方法名())
<top ref="topComponent"></top>
3.为for循环出来的组件添加动态值 :ref=变量
<div class="item" v-for="(item,index) in listData" :ref="item.name"></div>
ref本身是作为渲染结果被创建的,在初始渲染时还不存在,因此不能被访问,$refs也不是响应式的,因此不能将它用在模板中做数据绑定。
网友评论