Template refs的作用
使得Vue可以直接访问DOM。比如,装载页面后使得文本框获得输入焦点。
markup
<template>
<input type="text" ref="inputRef" />
</template>
<script>
export default {
name: 'test',
mounted() {
this.$refs.inputRef.focus();
}
}
</script>
除了标准的HTML元素,也可以使用ref来引用自定义组件:
markup
<StudentList ref="studentListRef" />