Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

535
Views
Quiero crear un botón activar/desactivar en vue

Esta es mi mesa. Como puedes ver he añadido un botón para realizar una acción.

La acción debe cambiar de activo a no activo y de no activo a activo al hacer clic.

Parece que no puedo encontrar el área de SQL a la que puedo acceder, lo que me dificulta actualizar la base de datos al hacer clic. Cualquier sugerencia o ayuda será muy apreciada.

Si hay alguna forma de actualizar la base de datos al hacer clic en este botón, el nuevo valor también debería aparecer en la tabla de datos.

 <table class="table" id="myTable"> <thead> <tr> <th>Status</th> <th>Action</th> </tr> </thead> <tbody> <tr v-for="product in filteredProducts" :key="product.id"> <td>{{ product.status }}</td> <td> <div class="btn-group" role="group"> <button class="btn btn-secondary" @click="acdcProduct(product.id)">Active/Deactive</button> </div> </td> </tr> </tbody> </table>

Esto es lo que he intentado hacer hasta ahora. Lo siento, soy nuevo en vue.js

 acdcProduct(id) { this.axios .acdc(`http://localhost:8000/api/products/${id}`) let i = this.products.map(data => data.id).indexOf(id); this.products.status(i, active) }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Ejemplo para el lado vue, también debe verificar si la actualización de la base de datos fue exitosa:

 new Vue({ el: '#demo', data() { return { products: [ {id: 1, name: 'prod 1', status: false}, {id: 2, name: 'prod 2', status: false}, {id: 3, name: 'prod 3', status: false}, {id: 4, name: 'prod 4', status: false}, {id: 5, name: 'prod 5', status: false}, ] } }, methods: { acdcProduct(id) { /*this.axios .acdc(`http://localhost:8000/api/products/${id}`)*/ let i = this.products.map(data => data.id).indexOf(id); this.products[i].status = !this.products[i].status } } })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="demo"> <table class="table" id="myTable"> <thead> <tr> <th>Status</th> <th>Action</th> </tr> </thead> <tbody> <tr v-for="product in products" :key="product.id"> <td>{{ product.status ? 'active' : 'deactive' }}</td> <td> <div class="btn-group" role="group"> <button class="btn btn-secondary" @click="acdcProduct(product.id)" > Active/Deactive </button> </div> </td> </tr> </tbody> </table> </div>

about 4 years ago · Juan Pablo Isaza Report

0

deje que filteredProducts sea una matriz la primera vez que tiene todos los datos del producto y, después de actualizar los datos del producto, tiene una matriz de productos de actualización en respuesta y nuevamente actualiza la matriz de filteredProducts con nuevos datos actualizados.

 let filteredProducts = []; acdcProduct(id) { axios({ method: "PUT", url: `http://localhost:8000/api/products/${id}`, }).then((res) => { filteredProducts = res.data }); }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!