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

193
Vistas
Vue.js - how to send send GET request with id as path params

I want to send GET request to my backend app and pass ID as a query params. The path I want to use is - GET /api/v1/imports/products_batches/:id. Here is my code:

imports.js

const fetchSyncedProductsResultRequest = (token, id) => {
  return axios
    .get(`/api/v1/imports/products_batches`, {
      params: { id: id },
      headers: {
        Authorization: `Bearer ${token}`,
      }
    })
    .then(response => {
      return response.data['result']
    })
};

sync_products.vue

<template>
  <div>
    <div class="col-12 col-md-3">
      <button
        type="button"
        class="btn btn-primary"
        @click="syncProducts"
      >
        Sync
      </button>
    </div>
  </div>
</template>

<script>

import {
  fetchSyncedProductsResultRequest,
} from '../../api/imports'

export default {
  name: 'BackboneSyncProducts',
  data() {
    return {
      fetchedProductSyncResult: [],
    }
  },
  methods: {
    async syncProducts() {
      let confirmationText = `Do you want to ${this.productsToSyncAmount} sync products?`

      if (this.productsToSyncAmount === 0) {
        ModalController.showToast('', 'Type product codes for sync first, please!', 'warning')
      }
      else if (await ModalController.showConfirmation('Confirmation', confirmationText)) {
        try {
          ModalController.showLoader()
          await fetchSyncedProductsResultRequest(this, '43').then(data => {
            console.log(data)
            this.fetchedProductSyncResult = data
          })
          // await createApparelMagicProductsRequest(this, this.styleCodes).then(data => {
            // this.loadId = data['id']
          // })
          const successMessage = `${this.productsToSyncAmount} products have been queued for sync`
          await ModalController.showToast('', successMessage)
        } catch (data) {
          const errorMessage = `Error occurred during queueing products to sync - `
          ModalController.showToast('', errorMessage + data?.message, 'error')
        } finally {
          this.styleCodes = []
          ModalController.hideLoader()
        }
      }
    },
  }
}
</script>

As you see, I've hardcoded id=43 and added console.log here:

          await fetchSyncedProductsResultRequest(this, '43').then(data => {
            console.log(data)
            this.fetchedProductSyncResult = data
          })

and it returns me undefined.

I don't know, am I sending the query params not correctly or am I have a typo somewhere? How to send this request correctly ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Replace your

axios
    .get(`/api/v1/imports/products_batches`, ...

with

axios
    .get(`/api/v1/imports/products_batches/${id}`, ...
about 4 years ago · Juan Pablo Isaza 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