最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I change variant of Bootstrap Vue button style checkboxes when clicked - Stack Overflow

programmeradmin3浏览0评论

I have utilised bootstraps button style checkboxes in a Vue JS project of mine, which works correctly and as it should, however, I want the button style checkboxes variant to change from outline-secondary to success when clicked.

Could someone please advise on how this could be achieved?

Below is a code snippet showing the options defaulted to the outline-secondary variant.

<template>
  <div>
    <b-form-group>
      <b-form-checkbox-group v-model="selected"
                             buttons
                             button-variant="outline-secondary"
                             name="buttons2"
                             :options="options">
      </b-form-checkbox-group>
    </b-form-group>
  </div>
</template>

<script>
export default {
  data () {
    return {
      selected: [],
      options: [
        {text: '1 week', value: '1 week'},
        {text: '1 month', value: '1 month'},
        {text: '1 year', value: '1 year'},
        {text: '1 decade', value: '1 decade'}
      ]
    }
  }
}
</script>

Any help would be hugely appreciated.

Cheers,

Ant

I have utilised bootstraps button style checkboxes in a Vue JS project of mine, which works correctly and as it should, however, I want the button style checkboxes variant to change from outline-secondary to success when clicked.

Could someone please advise on how this could be achieved?

Below is a code snippet showing the options defaulted to the outline-secondary variant.

<template>
  <div>
    <b-form-group>
      <b-form-checkbox-group v-model="selected"
                             buttons
                             button-variant="outline-secondary"
                             name="buttons2"
                             :options="options">
      </b-form-checkbox-group>
    </b-form-group>
  </div>
</template>

<script>
export default {
  data () {
    return {
      selected: [],
      options: [
        {text: '1 week', value: '1 week'},
        {text: '1 month', value: '1 month'},
        {text: '1 year', value: '1 year'},
        {text: '1 decade', value: '1 decade'}
      ]
    }
  }
}
</script>

Any help would be hugely appreciated.

Cheers,

Ant

Share Improve this question asked Jul 30, 2018 at 17:42 AntChamberlinAntChamberlin 531 gold badge1 silver badge10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

My quickest solution for this would be:

  <div class="my-buttons">
    <b-form-group>
      <b-form-checkbox-group v-model="selected"
                             buttons
                             button-variant="outline-secondary"
                             name="buttons2"
                             :options="options">
      </b-form-checkbox-group>
    </b-form-group>
  </div>


<style>
  .my-buttons .active {
    color: #fff !important;
    background-color: #28a745 !important;
    border-color: #28a745 !important;
  }
</style>

I have added parent class my-buttons and overlapped class .active. Because your checkbox will get that .active class when you click on it and it bees checked.

发布评论

评论列表(0)

  1. 暂无评论