Skip to content

Instantly share code, notes, and snippets.

@fLipE23
Created February 3, 2020 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fLipE23/7f0e9614677a73650c3516de985fd1af to your computer and use it in GitHub Desktop.
Save fLipE23/7f0e9614677a73650c3516de985fd1af to your computer and use it in GitHub Desktop.
custom vue-input :: btn-group
<template>
<div class="btn-group " role="group">
<button type="button" :class="getClassForOption(option)"
v-for="option in options"
@click="setValue(option)">{{option.title}}</button>
</div>
</template>
<script>
export default {
mounted() {
},
props: {
// варианты выбора, [{title: 'Example title', value: 'Example value',}, ... ]
options: {
type: Array,
required: true,
default() {
return []
},
},
// возвращаемое значение
value: {
// type: Number,
required: false,
default() {
return false
},
},
active_class: {
type: String,
required: false,
default() {
return 'btn-primary'
},
},
not_active_class: {
type: String,
required: false,
default() {
return 'btn-default'
},
},
},
data() {
return {
// текущее значение - по умолчанию передано из родителя
current_value: this.value,
}
},
methods: {
setValue(option) {
this.current_value = option.value
this.$emit('input', this.current_value)
},
getClassForOption(option) {
return [
'btn',
(option.value === this.current_value ? 'btn-primary' : 'btn-default'),
]
},
},
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment