const ColumnI = {
name: 'column-i',
template: `<component :is="tag" :class="columnClass"><slot /></component>`,
props: {
// This prop will not be converted into a class
tag: {
Type: String,
default: 'div',
},
xs: {
Type: Number,
default: null,
},
md: {
Type: Number,
default: null,
},
lg: {
Type: Number,
default: null,
},
},
data() {
return {
breakpoints: ['xs', 'md', 'lg'],
}
},
computed: {
columnClass() {
let result = ['column']
// Look for all the component props and get an array of all its
// enumerable [key, value] pairs
for (let [propKey, propValue] of Object.entries(this.$props)) {
// If the prop is a breakpoint and it has a value
if (this.breakpoints.includes(propKey) && propValue) {
// Add the prop to the class as '<key><value>'
// ie. xs prop with a value of 3 results in 'xs3'
result.push(`${propKey}${propValue}`)
}
}
return result
},
},
}
new Vue({
el: '#app',
components: {
ColumnI,
}
})
/*
Random styles just for illustration purposes
*/
.tagdiv {
/* This will not be applied */
text-decoration: underline;
}
.column {
padding: 10px;
}
.xs3 {
color: dodgerblue;
}
.md6 {
background-color: whitesmoke;
}
.lg12 {
border: 2px solid tomato;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<column-i xs="3" md="6" lg="12">
Some Content
</column-i>
</div>