Combining multiple v-if conditions on a single Vuejs element

Hey there, I'm currently facing an issue with v-if in Vue.

Basically, I have a v-for loop that iterates through an array and within that loop, I have a few elements with v-if conditions:

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

However, I would like to also disable the "activate" buttons if a specific data variable (disableButton) is set to true. Any ideas on how I could achieve this?

It might seem like a simple question, but as someone new to Vue, I've been searching for a solution for quite some time now.

Answer №1

Here is a code snippet you can try:

const app = new Vue({
  el: '#demo',
  data() {
    return {
      items: [{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="item in items" :key="item.id">
        <button v-if="item.status" type="button" >deactivate</button>
        <button v-else :disabled="disableButton" type="button">activate</button>
  	</li>
  </ul>
</div>

Answer №2

Are you searching for this?

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the total number of webgl.draw calls generated by Three.js when rendering a specific quantity of geometries, materials, and meshes?

Can you help me determine the total drawArrays/drawElements calls required by THREE.renderer.render(scene, camera)? I speculate one call per geometry, incorporating attributes for materials/mesh properties. Is my assumption accurate or am I overlooking ce ...

Error in Nuxt with Octoin-vue: identifier not recognized

For my project written in nuxt.js, I wanted to incorporate icons from Octicon. To achieve this, I decided to utilize the Octicon Component for Vue.js available here. I created a file named octicon.js and placed it in the /plugins directory, then registere ...

What's the best way to show floating point numbers in a concise format while also maintaining the ability to perform calculations within this Vue app?

I'm currently developing a compact calculator application using Vue 3 and implementing some custom CSS. For the most part, everything seems to be functioning correctly, except for when the results are long numbers that extend beyond the display limit ...

Is it possible to automate the process of data being sent to a website? (Using Python with Flask, WSGI, and

Is there a way to automatically push a value onto a website (using AJAX with JQuery) when something is completed on the server side in Python, rather than just responding to a request by the website? How can I prepare JQuery to receive this adhoc data? S ...

Tips for hiding a bootstrap tooltip when an element is no longer in the DOM

I'm currently working on a project in ReactJS. Some of my components are not always rendered but change dynamically based on certain conditions. I've run into an issue where if a tooltip is active on a hidden element, it doesn't disappear wh ...

What is the best way to utilize global variables in React JS?

import React, {useEffect, useState } from 'react'; import axios from 'axios'; function DisplayWeather(){ useEffect(()=>{ const fetchApiData = async ()=>{ var apiKey =""; const response = await axios ...

What's the best way to include php variables in this Javascript code?

I'm currently in the process of constructing a straightforward news page that utilizes ajax filters based on the user's selected category. The javascript code below establishes a connection with a php file and generates HTML using data from a mys ...

Issues with triggering functions through an input with Vue.js on a Samsung S9 are preventing the intended function from

After typing 3 characters, the function should be called. This functionality is working on desktop and other devices, but not on Samsung devices. It only works after entering a space or closing the mobile keyboard. My expectation is that the function shoul ...

How can I write an if-else statement in JavaScript with Mongoose for MongoDB?

I am facing a challenge where I need to execute a statement only if the object is not null. If the object is null, I should skip executing anything. Is there a correct way to achieve this? I attempted it on MongoDB Playground but unfortunately, it did not ...

How can I conditionally disable a button in Vue.js using an if statement?

Can someone help me figure out why all my buttons are getting disabled when I only want one to be disabled? Here is the code where I created a counter with vue.js: <body> <div id="app"> <button @click="co ...

I am selecting specific items from a list to display only 4 on my webpage

I am trying to display items from a list but I only want to show 4 out of the 5 available items. Additionally, whenever a new item is added, I want it to appear first on the list, with the older items following behind while excluding the fifth item. Despi ...

Create a personalized attribute for division automation

Is it possible to automatically divide a dynamically populated ListView in jQuery-mobile into two groups based on the attribute values (Downloaded/Not downloaded)? Some listitems have the attribute status="true" while others have status="false". Here is t ...

Remove hidden data upon moving cursor over table rows after a delay

Hey there! I'm in need of a little assistance, so I hope you can lend me a hand. Here's the scenario: Within my category table, there are numerous rows, each containing a hidden textbox with an empty value and a unique ID. As users navigate t ...

Iterate through the list elements by utilizing jQuery

I am working with HTML code that looks like this: <ul class="lorem"> <li>text</li> <li>text</li> <li>hello</li> <li>text</li> </ul> Can someone help me figure out how to loop through ...

Input various information into a single form multiple times and automatically submit it to a Google spreadsheet

I have some data that needs to be transferred to an array and then sent to a Google Sheet. The data looks like this: -|PO: 2005 | 12121211212121,| Qty: 45| BIN:110| eBay| 11/6/2017-| PO: 2165 | 333333333,| Qty: 54| BIN:20| google| 11/6/2017- First, I use ...

Utilizing JSON data to create dynamic HTML content for Isotope.js filtering

UPDATE: After struggling to understand the previous answers, I have revised this question for clarity. As a beginner, I hope this simplified version can benefit others like me... I want to utilize isotope.js to showcase specific data from a JSON source (r ...

What is the best way to organize React components that need to retrieve data from a modal?

At this moment, my React container is structured like so: class TableData extends Component { some React Functions and state changes. <Sidebar passdata as props/> } Within the Sidebar component, there is a modal that needs to update the state of b ...

Emulating a button press on the login screen

I have been attempting to utilize jQuery to simulate a button click on a login page. Interestingly, the conventional JavaScript method functions as expected: document.getElementById('loginButton').click(); However, the same action using jQuery ...

What is the proper procedure for configuring Babel and executing "npm run dev" in the terminal without encountering the "ERROR in ./src/js/index.js" message?

My goal is to include the babel/polyfill with the index.js files using webpack. After completing the setup, I tried running "npm run dev" in the command prompt but encountered an error. The initial line of the error message said "ERROR in ./src/js/index.js ...

Utilizing IonicSafeString for Alert Box Messages in Event Handling

.ts private async displayTermsOfServiceAlert(): Promise<void> { const alert = await this.alertController.create({ header: 'Updated Terms of Service', //problem lies here message: new IonicSafeString(`<ion-button i ...