0

sup, so I have a problem with v-if in vue.

basicly I have a v-for that loops thru array and inside that v-for I have a couple of elements with v-if

<button v-if="Collection.status" type="button">deactivate</button>
<button v-else type="button">activate</button>

but I would also like to disable "activate" buttons if a data variable (disableButton) is true. How could I do that?

Its maybe a silly question but im new to vue and i have been searching for this for to long.

3
  • Disable or hide the activate button? (your example is hiding [not rendering] it) Commented Oct 14, 2021 at 21:06
  • Basicly if "Activate" button renders and data variable is true I'd also like to disable that button @SteveHynding Commented Oct 14, 2021 at 21:09
  • Do you still want to hide/not-render the "activate" button if Collection.status evaluated to true? Commented Oct 14, 2021 at 21:16

2 Answers 2

1

Try like following snippet:

new Vue({
  el: '#demo',
  data() {
    return {
      Collections: [{id: 1, status: true}, {id: 2, status: false}, {id: 3, status: true}],
      disableButton: true
    }
  }
})

Vue.config.productionTip = false
Vue.config.devtools = false
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
  <ul>
    <li v-for="Collection in Collections" :key="Collection.id">
      <button v-if="Collection.status" type="button" >deactivate</button>
      <button v-else :disabled="disableButton" type="button">activate</button>
    </li>
  </ul>
</div>

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

Comments

0

are you looking for this?

<button v-else type="button" disable="Collection.disableButton">activate</button>

Comments

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.