Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
How do I update my list data when data is already sent in the backend? (VUE/DJANGO)

I'm new to vue and trying to work it with django. I have a field called status that uses boolean field and set the default=False. I'm trying to update the data in the backend by onclick. When i click the div, data will emit to parent and update the status to !status.

Child:

<div @click="$emit('update-status', this.task)">{{ task.status}} </div>

Parent:

<Task v-for="task in tasks"
      :key="task.slug"
      :task="task"
      :slug="task.slug"
      @update-status="updateStatus"/>


async updateStatus(task) {
 let endpoint = `/api/v1/tasks/${task.slug}/`;
 const response = await axios.put(endpoint, {
       status: !task.status,
 
      });
    }

It updates once and it keeps returning the same value True when I keep on clicking (it should always return opposite of status). I have to manually refresh my browser, so when I click it again it will return False.

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

If you get your updated object in response, you can simply update your tasks:

Vue.component('task', {
  template: `
    <div @click="$emit('update-status', task)">{{ task.status }}</div>
  `,
  props: {
    task: Object
  }
})

new Vue({
  el: '#demo',
  data() {
    return {
      tasks: [{slug: 'a', status: false}, {slug: 'b', status: false}]
    }
  },
  methods: {
    async updateStatus(task) {
     //let endpoint = `/api/v1/tasks/${task.slug}/`;
     /*const response = await axios.put(endpoint, {
         status: !task.status,
      });*/
      const response = {slug: task.slug, status: !task.status}
      this.tasks = this.tasks.map(t => (t.slug === response.slug) ? response : t)
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
  <Task v-for="task in tasks"
      :key="task.slug"
      :task="task"
      :slug="task.slug"
      @update-status="updateStatus"/>
</div>

about 4 years ago · Santiago Trujillo Denunciar

0

Thanks to @Nikola Pavicevic answer

I modified the data to also send it in the backend.

async updateStatus(task) {
      let endpoint = `/api/v1/tasks/${task.slug}/`;
      const data = {
        slug: task.slug,
        status: !task.status,
      };
      const response = await axios.put(endpoint, data);
      this.tasks = this.tasks.map((task) =>
        task.slug === data.slug ? data : task
      );
    
    },
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda