1

i wrote like this but when i press the button all comboboxes show up but i want when i press the button in any combobox only that combobox will show up
HTML

             <div class="m-combobox">
                <div class="select-list" :class="{'sl-activate':isActivate}">
                    <div class="select-item" v-for="item in departments" :key="item.DepartmentId">
                        <i class="fas fa-check"></i>
                        <div class="select-item-text">{{item.DepartmentName}}</div>
                    </div>
                </div>
                <div class="select">
                    <input class="m-combobox-input" type="text" placeholder="Chọn/Nhập thông tin">
                    <div class="m-combobox-button" @click="activateCbb">
                        <i class="fas fa-angle-down"></i>
                    </div>
                </div>
            </div>
            <div class="m-combobox">
                <div class="select-list" :class="{'sl-activate':isActivate}">
                    <div class="select-item" v-for="item in positions" :key="item.PositionId">
                        <i class="fas fa-check"></i>
                        <div class="select-item-text">{{item.PositionName}}</div>
                    </div>
                </div>
                <div class="select">
                    <input class="m-combobox-input" type="text" placeholder="Chọn/Nhập thông tin">
                    <div class="m-combobox-button" @click="activateCbb">
                        <i class="fas fa-angle-down"></i>
                    </div>
                </div>
            </div>


data

data: function () {
return {
  positions: [],
  departments: [],
  isActivate: false,
};
}


Method

methods:{
activateCbb() {
  this.isActivate = !this.isActivate;
},
}

Tks all!

1 Answer 1

1

Try like following snippet:

new Vue({
  el: '#demo',
  data() {
    return {
      positions: [{PositionId:1, PositionName:'ccc'}, {PositionId:2, PositionName:'ddd'}],
      departments: [{DepartmentId:1,DepartmentName: 'aaa'}, {DepartmentId:2,DepartmentName: 'bbb'}],
      isActivate: null,
    };
  },
  methods:{
    activateCbb(type) {
      if(this.isActivate === type) {
        this.isActivate = null
      } else {
        this.isActivate = type
      }
    },
  }
})

Vue.config.productionTip = false
Vue.config.devtools = false
.sl-activate {
  display: block;
}
.inactive {
  display: none;
}
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
  <div class="m-combobox">
      <div class="select-list" :class="isActivate === 'd' ? 'sl-activate' : 'inactive'">
          <div class="select-item" v-for="item in departments" :key="item.DepartmentId">
              <i class="fas fa-check"></i>
              <div class="select-item-text">{{item.DepartmentName}}</div>
          </div>
      </div>
      <div class="select">
          <input class="m-combobox-input" type="text" placeholder="Chọn/Nhập thông tin">
          <div class="m-combobox-button" @click="activateCbb('d')">
              <i class="fas fa-angle-down"></i>
          </div>
      </div>
  </div>
  <div class="m-combobox">
      <div class="select-list" :class="isActivate === 'p' ? 'sl-activate' : 'inactive'">
          <div class="select-item" v-for="item in positions" :key="item.PositionId">
              <i class="fas fa-check"></i>
              <div class="select-item-text">{{item.PositionName}}</div>
          </div>
      </div>
      <div class="select">
          <input class="m-combobox-input" type="text" placeholder="Chọn/Nhập thông tin">
          <div class="m-combobox-button" @click="activateCbb('p')">
              <i class="fas fa-angle-down"></i>
          </div>
      </div>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

it's working tks u so much. Can you give me your contact info I'm newbie so I'd love to message you directly so I can ask you for more help with vue and js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.