Vue.js Get Screen Width


We can use screen width property to get the total width of the device screen. Here in this tutorial, we are going to explain how you can use screen width object to get the width of the screen. You can also use our online editor to edit and run the code online.


Vue.js get screen Width Example

You can get device screen width in vuejs simply as below-

Example:

<div id="app">
	<p>{{result}}</p>
	<button @click="myFunction()">Click Me</button>
</div>
<script>
 new Vue({
el: '#app',
  
  data: { 
	  result:""
  },
  
   methods:{
    myFunction: function () {	
		this.result = screen.width+"px";
    }
   }

});
</script>      

Try it »

Output of above example-

Vue.js Get Screen Width

Advertisements

Add Comment

📖 Read More