ref可以给子组件或元素注册特殊自定义属性,在模板中使用ref属性,在VUE实例可以通过$ref访问对应元素或组件
eg:
1、给html元素注册,通过this.$ref.self可以访问到定义该属性的DOM元素
//给div添加ref属性
<template>
<div ref="self"></div>
</template>
//通过this.$ref.self可以访问到定义该属性的DOM元素
2、给子组件注册,通过this.$ref.myComonent可以访问到定义该属性的子组件
//给子组件child-component,添加ref属性
<template>
<child-component ref="myComponent"></child-component>
</template>
此外,可以通过this.$ref.myComonpent.组件方法(),访问子组件中的方法