项目作者: jjcosgrove

项目描述 :
A simple Vue plugin/mixin to augment your Vue instance with breakpoint helpers
高级语言: JavaScript
项目地址: git://github.com/jjcosgrove/vue-breakpointer.git
创建时间: 2018-09-16T13:25:11Z
项目社区:https://github.com/jjcosgrove/vue-breakpointer

开源协议:MIT License

下载


Vue Breakpointer

A simple Vue plugin/mixin to augment your Vue instance with breakpoint helpers

Install

NPM/Yarn

  1. npm install vue-breakpointer --save

or

  1. yarn add vue-breakpointer --save

Browser

  1. <script src="https://unpkg.com/vue-breakpointer"></script>

Plugin

  1. import VueBreakpointer from 'vue-breakpointer'
  2. ...
  3. Vue.use(VueBreakpointer, {
  4. // defaults
  5. breakpoints: {
  6. sm: 576,
  7. md: 768,
  8. lg: 992,
  9. xl: 1200
  10. }
  11. })
  12. ...

Mixin

  1. import { VueBreakpointerMixin } from 'vue-breakpointer'
  2. ...
  3. export default {
  4. ...
  5. mixins: [ VueBreakpointerMixin ],
  6. data () {
  7. return {
  8. // defaults
  9. breakpoints: {
  10. sm: 576,
  11. md: 768,
  12. lg: 992,
  13. xl: 1200
  14. }
  15. }
  16. }
  17. ...
  18. }
  19. ...

Data & Computed Properties

Property Type Description
windowDimensions Object On object containing both the current window width & height (in pixels)
xs Boolean < sm
sm Boolean >= sm && < md
md Boolean >= md && < lg
lg Boolean >= lg && < xl
xl Boolean >= xl

Example usage

  1. <template>
  2. <div>
  3. <!-- an object showing both width and height of window -->
  4. <pre>{{windowDimensions}}</pre>
  5. <!-- the current breakpoint -->
  6. <pre>{{breakpoint}}</pre>
  7. <!-- use to determine visibility of elements and components at certain breakpoints -->
  8. <div v-if="xs">I am visible only on xs screens</div>
  9. <div v-if="sm">I am visible only on sm screens</div>
  10. <div v-if="md">I am visible only on md screens</div>
  11. <div v-if="lg">I am visible only on lg screens</div>
  12. <div v-if="xl">I am visible only on xl screens</div>
  13. </div>
  14. </template>

Example

https://jsfiddle.net/5k6v07br/