Skip to content

Ability to set defaultBreakpoint dynamically in nuxt module #54

@cainaf

Description

@cainaf

Feature Suggestion
Add the possibility to set the defaultBreakpoint dynamically when using nuxt module.

Why?
To prevent misbehavior of components when reloading a page in a screen size that is not the default. Components that depends on $mq are wrongly shown or hidden while vue-mq is not fully loaded in the frontend application, causing a blink of very misplaced ui components for a few seconds.

Suggested solution
With SSR it's possible to have a header telling the screen size of origin request. We could have something like:

/**
* nuxt-mq
*/
mq: {
  defaultBreakpoint: (req) => {
    if (req.headers['CloudFront-Is-Mobile-Viewer']) {
      return 'modernPhone';
    }
    if (req.headers['CloudFront-Is-Tablet-Viewer']) {
      return 'tablet';
    }
    return 'desktop';
  },
  breakpoints: {
    oldPhone: 375, // 0 ~ 374
    modernPhone: 800, // 375 ~ 799
    tablet: 1000, // 800 ~ 999
    notebook: 1200, // 1100 ~ 1199
    desktop: Infinity, // 1300+
  },
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions