Detect mobile device in Vue.js

in Code Write a comment

In this tutorial, you’ll learn how to detect whether or not a user is using a mobile device in Vue.js.

You can use an npm-package called vue-mobile-detection.


npm i -S vue-mobile-detection

Not let’s add import this package to main.js file:

import VueMobileDetection from 'vue-mobile-detection'


You can now use this.$isMobile() function both in a template and in a JavaScript. It will return a Boolean value.

Hi, I'm Renat 👋


  <div id="app">
    <div v-if="$isMobile()">MOBILE</div>
    <div v-else>DESKTOP OR TABLET</div>

export default {
  created() {

If you find this post useful, please let me know in the comments below and subscribe to my newsletter. 
Renat Galyamov

Want to share this with your friends?

PS: Make sure you check other Vue.js tutorials, e.g. how to password protect your website in Vue.js, how to add current date to input type date in Vue.jshow to deploy Vue.js app to Firebase hosting.

Incoming search terms:

A collection of UI components for
Bootstrap 4/5 and Vue.js

Get now

Write a Comment