screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Load Vuetify styles --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vuetify@3.1.11/dist/vuetify.min.css"> </head> <body> <div id="app"> <v-app> <v-main> <v-container> <v-card> <v-card-title class="text-center"> <h3>Vuetify Display Breakpoint Example| Get Screen size</h3> </v-card-title> <v-card-text> <p class="text-center">Screen Size: {{ screenSize }}</p> <p class="text-center">Screen Width: {{ screenWidth }}</p> <p class="text-center">Screen Height: {{ screenHeight }}</p> </v-card-text> </v-card> </v-container> </v-main> </v-app> </div> <!-- Load Vue.js and Vuetify script --> <script src="https://unpkg.com/vue@3.2.21/dist/vue.global.js"></script> <script src="https://cdn.jsdelivr.net/npm/vuetify@3.1.11/dist/vuetify.min.js"></script> <script type="module"> const { createApp } = Vue const { createVuetify } = Vuetify const vuetify = createVuetify() const app = createApp({ data() { return { screenSize: '', // To store the screen size screenWidth: '', screenHeight: '' }; }, mounted() { window.addEventListener('resize', this.onResize); this.onResize(); // Initial call to set the initial values }, beforeUnmount() { window.removeEventListener('resize', this.onResize); }, methods: { onResize() { this.screenWidth = window.innerWidth; this.screenHeight = window.innerHeight; if (this.screenWidth < 600) { this.screenSize = 'Extra small (xs)'; } else if (this.screenWidth < 960) { this.screenSize = 'Small (sm)'; } else if (this.screenWidth < 1264) { this.screenSize = 'Medium (md)'; } else if (this.screenWidth < 1904) { this.screenSize = 'Large (lg)'; } else { this.screenSize = 'Extra large (xl)'; } }, }, }).use(vuetify).mount('#app'); </script> </body> </html>