screen_rotation
Copied to Clipboard
<html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h3>Vue.js to Detect user's device type </h3> <P v-if="deviceType">Device Type: {{ deviceType }}</P> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { deviceType: null, }; }, mounted() { this.setDeviceType(); }, methods: { setDeviceType() { const platform = navigator.platform.toLowerCase(); if (/(android|webos|iphone|ipad|ipod|blackberry|windows phone)/.test(platform)) { this.deviceType = 'mobile'; } else if (/mac|win|linux/i.test(platform)) { this.deviceType = 'desktop'; } else if (/tablet|ipad/i.test(platform)) { this.deviceType = 'tablet'; } else { this.deviceType = 'unknown'; } }, }, }); </script> </body> </html>