Created
December 20, 2018 14:55
-
-
Save pixelbacon/ba6e92aec8786b92469ed5544a5a814f to your computer and use it in GitHub Desktop.
vue-responsive-components helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _ from 'lodash'; | |
const cssName = nameStr => _.lowerFirst(nameStr); | |
export default cssName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue'; | |
import { ResponsiveMixin } from 'vue-responsive-components'; | |
import cssName from '@/lib/cssName'; | |
Vue.mixin(ResponsiveMixin); | |
// Helper previous mixin | |
const responsiveHelper = { | |
created() { | |
this.cssName = cssName(this.$options.name); | |
this.responsive = { | |
[`${this.cssName}--xs`]: el => el.width < 600, | |
[`${this.cssName}--sm`]: el => el.width >= 600 && el.width < 960, | |
[`${this.cssName}--md`]: el => el.width >= 960 && el.width < 1264, | |
[`${this.cssName}--lg`]: el => el.width >= 1264 && el.width < 1600, | |
[`${this.cssName}--xl`]: el => el.width >= 1600, | |
}; | |
}, | |
data: () => ({ | |
cssName: null, | |
responsive: null, | |
}), | |
}; | |
Vue.mixin(responsiveHelper); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment