SoFunction
Updated on 2025-04-05

How to get the content of dom element in vue

In vue, you can use ref attribute to the tag to reference it in js to operate the dom element. The following is an example, which can be used as a reference

<template> 
 <div> 
  <div  ref="mybox"> 
   DEMO 
  </div> 
 </div> 
</template> 
 
<script> 
export default { 
 data () { 
  return { 
    
  } 
 }, 
 mounted () { 
  (); 
 }, 
 methods:{ 
  init() { 
   const self = this; 
   this.$ = 'red'; 
   setTimeout(() => { 
    self.$ = 'blue'; 
   },2000) 
  } 
 } 
 
} 
</script> 
 
<style scoped> 
 #box { 
  width: 100px; 
  height: 100px; 
  line-height: 100px; 
  font-size: 20px; 
  text-align: center; 
  border: 1px solid black; 
  margin: 50px;  
  color: yellow; 
 } 
</style> 

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.