用ref操作模版中的dom元素
1.在模版中,声明ref名称
<div ref="chagneBack" @click='change'> ref引用Dom节点 </div>
2.用法
change(){
this.$refs.chagneBack.style.color="red"
},
用ref操作组件
1.在组件引用中声明ref名称
<Left ref="doaction"></Left>
2.在方法中,可以用this.$refs.doaction.来操作子组件中的方法和变量
用ref遇到的问题
当用ref获取dom元素时,必须要等页面有这个元素,如果需要等待页面
this.$nextTick(()=>{
this.$refs.iptfocus.focus()
})