我是靠谱客的博主 慈祥秀发,这篇文章主要介绍vue中ref属性,现在分享给大家,希望可以做个参考。

作用:

获取原生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属性内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(101)

评论列表共有 0 条评论

立即
投稿
返回
顶部