项目作者: wearelucid

项目描述 :
Vue Media Queries
高级语言: JavaScript
项目地址: git://github.com/wearelucid/vue-mq.git
创建时间: 2017-06-16T17:00:26Z
项目社区:https://github.com/wearelucid/vue-mq

开源协议:MIT License

下载


vue-mq

@wearelucid/vue-mq"">npm version
JavaScript Style Guide license

Note: Draft, not quite production ready.

Vue.js 2.0+ plugin for media queries.

Installation

  1. yarn add @wearelucid/vue-mq

Integration

  1. import { MediaQueries } from 'plugins/mediaqueries'
  2. // Define your breakpoints or import them from elsewhere
  3. const breakpoints = {
  4. small: 400,
  5. medium: 768,
  6. large: 1100,
  7. huge: 1400
  8. }
  9. Vue.use(MediaQueries, { breakpoints })

And then use it in your components

  1. // JSX Example
  2. Vue.component({
  3. // ...
  4. render (h) {
  5. return (
  6. <div>
  7. {this.$query({ from: 'medium' })
  8. ? 'Small Content'
  9. : 'Large Content'}
  10. </div>
  11. )
  12. }
  13. })

Use cases:

  1. this.$query({ from: 'medium' })
  2. this.$query({ from: 'small', to: 'large' })
  3. this.$query({ to: 'large' })

Or, as another example, display the currentBreakpoint

  1. // JSX Example
  2. Vue.component({
  3. name: 'DevStats'
  4. // ...
  5. render (h) {
  6. return (
  7. <span> Current Breakpoint: {this.$mq.current.name} @ {this.$mq.current.value}px </span>
  8. )
  9. }
  10. })

Todos

  • Validate reactive property. Is this correctly implemented? (mq, _mq, $mq)
  • Option to sync with CSS (e.g by reading breakpoints from JSON String, which we set ‘s font-size property)</li><li style="list-style: none;"><input type="checkbox" class="task-list-item-checkbox" /> Implement alternative way to pass in breakpoints</li><li style="list-style: none;"><input type="checkbox" class="task-list-item-checkbox" /> Tests</li><li style="list-style: none;"><input type="checkbox" class="task-list-item-checkbox" /> Npm Compat</li></ul> <h2 id="h2-browser-support"><a name="Browser Support" class="reference-link"></a><span class="header-link octicon octicon-link"></span>Browser Support</h2><p>IE8+ (<a href="https://tylercipriani.com/blog/2014/07/12/crossbrowser-javascript-scrollbar-detection/">See clientWidth</a>)<br>Uses <a href="https://developer.mozilla.org/en/docs/Web/API/Window/matchMedia">matchMedia</a> for newer browsers but has a polyfill for IE8/IE9.</p> <h2 id="h2-license"><a name="License" class="reference-link"></a><span class="header-link octicon octicon-link"></span>License</h2><p><a href="LICENSE">MIT</a></p>