{"id":13564015,"url":"https://github.com/AlexandreBonaventure/vue-mq","last_synced_at":"2025-04-03T20:32:38.892Z","repository":{"id":26527938,"uuid":"108748112","full_name":"AlexandreBonaventure/vue-mq","owner":"AlexandreBonaventure","description":"📱 💻   Define your breakpoints and build responsive design semantically and declaratively in a mobile-first way with Vue.","archived":false,"fork":false,"pushed_at":"2022-12-08T17:16:16.000Z","size":1894,"stargazers_count":537,"open_issues_count":56,"forks_count":59,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-29T17:14:04.778Z","etag":null,"topics":["breakpoints","media","mediaqueries","viewport","vuejs","vuejs2"],"latest_commit_sha":null,"homepage":"https://alexandrebonaventure.github.io/vue-mq","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlexandreBonaventure.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-29T15:52:06.000Z","updated_at":"2024-10-27T14:49:04.000Z","dependencies_parsed_at":"2022-09-20T17:54:45.800Z","dependency_job_id":null,"html_url":"https://github.com/AlexandreBonaventure/vue-mq","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexandreBonaventure%2Fvue-mq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexandreBonaventure%2Fvue-mq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexandreBonaventure%2Fvue-mq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexandreBonaventure%2Fvue-mq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexandreBonaventure","download_url":"https://codeload.github.com/AlexandreBonaventure/vue-mq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223030829,"owners_count":17076511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["breakpoints","media","mediaqueries","viewport","vuejs","vuejs2"],"created_at":"2024-08-01T13:01:25.561Z","updated_at":"2024-11-04T16:31:41.322Z","avatar_url":"https://github.com/AlexandreBonaventure.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","UI实用程序","Components \u0026 Libraries","UI Utilities","UI Utilities [🔝](#readme)"],"sub_categories":["响应式设计","UI Utilities","Responsive Design"],"readme":"# Vue MQ (MediaQuery)\nDefine your breakpoints and build responsive design semantically and declaratively in a mobile-first way with Vue.\n\n_Use with `vue:  ^2.x.x`\n_\n\n**Demo**: [here](https://alexandrebonaventure.github.io/vue-mq)\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [SSR Support](#ssr-support)\n- [Browser Support](#browser-support)\n- [Support](#support)\n\n\n## Installation\n\n#### Using NPM\n\n```sh\nnpm install vue-mq\n```\n#### Using Yarn\n```sh\nyarn add vue-mq\n```\n\n## Usage\n\n#### 1. Install plugin\nDefine your custom breakpoints by passing `breakpoints` option. This let you name the breakpoints as you want\n**Eg**:\n`{ phone: 500, tablet: 1200, other: Infinity }`\n`{ small: 500, large: 1200, whatever: Infinity }`\n`{ xs: 300, s: 500, m: 800, l: 1200, xl: Infinity }`\n```js\nimport Vue from 'vue'\nimport VueMq from 'vue-mq'\n\nVue.use(VueMq, {\n  breakpoints: { // default breakpoints - customize this\n    sm: 450,\n    md: 1250,\n    lg: Infinity,\n  }\n  defaultBreakpoint: 'sm' // customize this for SSR\n})\n```\n#### Use `$mq` property\nAfter installing the plugin every instance of Vue component is given access to a reactive $mq property. Its value will be a `String` which is the current breakpoint.\n\n**Eg:** _(with default breakpoints)_\n`'sm'` =\u003e **0 \u003e screenWidth \u003c 450**\n`'md'` =\u003e **450 \u003e= screenWidth \u003c 1250**\n`'lg'` =\u003e **screenWidth \u003e= 1250**\n\n```js\n//Use it in a component\nnew Vue({\n  template: `\n    \u003ch1\u003ecurrent: {{$mq}}\u003c/h1\u003e\n  `,\n})\n```\n\n#### Use `$mq` property with the mq filter\nUsing the filter allow to build your responsive design in a declarative way. This can be very useful and elegant to pass down props to layout component. (eg: a grid system)\n\n```js\nnew Vue({\n  template: `\n    \u003cgrid-component :column=\"$mq | mq({ sm: 1, md: 2, lg: 3 })\"\u003e\n    \u003c/grid-component\u003e\n  `,\n})\n```\n\nRemember that the filter design embrace mobile-first philosophy so writing `$mq | mq({ sm: 1, lg: 3 })` will output `1` for `md` breakpoint if omited. In short it will always fallback to the smallest breakpoint (_aka mobile_) if value isn't overriden by a largest breakpoint.\n\n\n#### Use `$mq` with a computed property\n`$mq` property is fully reactive (like a data property) so feel free to use it in a computed.\n\n```js\nnew Vue({\n  computed: {\n    displayText() {\n      return this.$mq === 'sm' ? 'I am small' : 'I am large'\n    }\n  },\n  template: `\n    \u003ch1\u003e{{displayText}}\u003c/h1\u003e\n  `,\n})\n```\n\n#### MqLayout component\nIn addition to `$mq` property this plugin provide a wrapper component to facilitate conditional rendering with media queries.\n\n**Usage**:\n```\n\u003cmq-layout mq=\"lg\"\u003e\n  \u003cspan\u003e Display on lg \u003c/span\u003e\n\u003c/mq-layout\u003e\n\u003cmq-layout mq=\"md+\"\u003e\n  \u003cspan\u003e Display on md and larger \u003c/span\u003e\n\u003c/mq-layout\u003e\n\u003cmq-layout :mq=\"['sm', 'lg']\"\u003e\n  \u003cspan\u003e Display on sm and lg \u003c/span\u003e\n\u003c/mq-layout\u003e\n```\n**Props**\nmq =\u003e required : String | Array\n\n*Important*: note that you can append a `+` modifier at the end of the string to specify that the conditional rendering happens for all greater breakpoints.\n\n## SSR Support\nv1.0+ now supports SSR. You can customize the `defaultBreakpoint` which let you set the breakpoint used by the server-side-rendering \n\n## Browser Support\nThis plugin relies on matchMedia API to detect screensize change. So for older browsers and IE, you should polyfill this out:\nPaul Irish: [matchMedia polyfill](https://github.com/paulirish/matchMedia.js)\n\n## Support\n\nPlease [open an issue](https://github.com/AlexandreBonaventure/vue-mq/issues/new) for support.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAlexandreBonaventure%2Fvue-mq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAlexandreBonaventure%2Fvue-mq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAlexandreBonaventure%2Fvue-mq/lists"}