作用:
获取原生js中的的dom元素(标签元素)或者vue中的组件元素。
与原生js属性用法比较:
1)该属性对应原生javascript中的id和class属性
//通过class或id查找元素
doucument.getElementByClass("school")
document.getElementById("school");
//通过class或id查找标签元素
document.queryElement(".school")
cocument.queryElement("#school")
2)vue中的ref属性
<template>
<div id="app">
<button ref = "but">按钮</button>
<School ref = "sch"/>
<span ref = "hi">你好啊</span>
</div>
</template>
<script>
//查找vue代码中的原生js标签或vue组件
this.$refs
</script>
最后
以上就是慈祥秀发最近收集整理的关于vue中ref属性的全部内容,更多相关vue中ref属性内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复