<h1 ref="hRef">h1标签</h1>
<button @click="fn">获取DOM</button>
import { onMounted, ref } from 'vue';
const hRef = ref(null)
onMounted(() => {
console.log(hRef);
console.log(document.getElementsByTagName('h1'));
console.log(hRef.value.innerText);
})
const fn = () => {
hRef.value.innerText = 'abc'
}
控制台打印结果
红框选中区域获取的数据相同
![](https://img-blog.csdnimg.cn/img_convert/66086d20ef7413eb5396942a933e3db6.png)