VOOZH about

URL: https://quasar.dev/options/screen-plugin/

⇱ Screen Plugin | Quasar Framework


assignment_late
Why donate
travel_explore
API Explorer
build
Quasar CLI (with Vite)
Upgrade Guide
Creating a New Project
The /quasar.config File
Convert q/app-webpack Project
Browser Compatibility
TypeScript Support
Directory Structure
Commands List
CSS Preprocessors
Page Routing with VueRouter
Lazy Loading - Code Splitting
Handling Assets
Boot Files
Prefetch Feature
API Proxying
Handling Vite
Handling import.meta.env
State Management with Pinia
Lint and Format Code
Testing & Auditing
Developing Mobile Apps
Ajax Requests
Opening Dev Server To Public
build
Quasar CLI (with Webpack)
Screen Plugin

The Quasar Screen plugin allows you to have a dynamic and responsive UI when dealing with your Javascript code. When possible, it is recommended to use the responsive CSS classes instead, for performance reasons.

Loading Screen API...

Usage

Notice $q.screen below. This is just a simple usage example.

<q-list :dense="$q.screen.lt.md">
 <q-item>
 <q-item-section>John Doe</q-item-section>
 </q-item>

 <q-item>
 <q-item-section>Jane Doe</q-item-section>
 </q-item>
</q-list>
// script part of a Vue component
import { useQuasar } from 'quasar'
import { computed } from 'vue'

export default {
 setup() {
 const $q = useQuasar()
 const buttonColor = computed(() => {
 return $q.screen.lt.md ? 'primary' : 'secondary'
 })

 return { buttonColor }
 }
}

We can also use the Screen plugin outside of a Vue component:

import { Screen } from 'quasar'

// Screen.gt.md
// Screen.md
// Screen.name ('xs', 'sm', ...)

Body classes

If you enable it (see how to do it after the examples below), you can also style your content based on a particular set of CSS classes applied to document.body: screen--xs, screen--sm, …, screen-xl.

body.screen--xs {
 .my-div {
 color: #000;
 }
}

body.screen--sm {
 .my-div {
 color: #fff;
 }
}

Or a sexy variant in Sass:

.my-div
 body.screen--xs &
 color: #000
 body.screen--sm &
 color: #fff

How to enable body classes

In order to enable the behavior above, edit your /quasar.config file like below. Please note that this will increase a bit the time for First Meaningful Paint.

/quasar.config file

framework: {
 config: {
 screen: {
 bodyClasses: true // <<< add this
 }
 }
}

Configuration

There are a few methods that can be used to tweak how Screen plugin works:

MethodDescriptionExample
setSizes(Object)Change window breakpoints; does NOT also changes CSS breakpoints.setSizes({ lg: 1024, xl: 2000 })
setDebounce(Number)Change the default 100ms debounce to some other value.setDebounce(500) // 500ms

Examples:

Inside a Vue component

import { useQuasar } from 'quasar'

setup () {
 const $q = useQuasar()

 $q.screen.setSizes({ sm: 300, md: 500, lg: 1000, xl: 2000 })
}
Outside of a Vue component

import { Screen } from 'quasar'
Screen.setSizes({ sm: 300, md: 500, lg: 1000, xl: 2000 })

Caught a mistake?Edit this page in browser
1. Introduction
2. Screen API
3. Usage
4. Body classes
4.1. How to enable body classes
5. Configuration
Copyright © 2015-present PULSARDEV SRL, Razvan Stoenescu