// 通过给元素绑定ref=“XXX”,然后通过this.$refs.XXX或者this.refs['XXX']来获取
<template>
<section>
<div ref="hello">
<h1>Hello World ~</h1>
</div>
<el-button type="danger" @click="get">点击</el-button>
</section>
</template>
<script>
export default {
methods: {
get() {
console.log(this.$refs['hello']);
console.log(this.$refs.hello);
}
}
}
</script>
VUE中获取DOM对象:
最新推荐文章于 2024-07-26 20:40:28 发布