Answers for "get id for component javascript vuejs"

0

vue get element by id

<!-- In template -->
<div id="myDiv" ref="myDiv">This is a div</div>

<!-- In script, inside a function or wherever you need it -->
<script>
	myDiv = this.$refs.myDiv
</script>
Posted by: Guest on August-20-2021
0

vue div id get div information

var app = new Vue({
    el:'#app',
    methods: {    
        showMyDiv() {
           console.log(this.$refs.myDiv);
        }
    }
    
   });
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<div id='app'>
   <div id="myDiv" ref="myDiv"></div>
   <button v-on:click="showMyDiv" >Show My Div</button>
</div>
Posted by: Guest on August-09-2021

Browse Popular Code Answers by Language