0

this is my vue file which accepts the id from table. this works I can get the data id from the table row

  showProd (id) {
   Products.showProd().then((response) => {
     console.log(show1prod.product_name)
   })
   .catch((error) => {
     alert(error)
   })

this is my config file for calling the axios.get I can reach the backend but not generating the query because this url/api sends an object I believe not the id number

export default {
    async showProd(id) {
        return Api.get('/products/{id}',id)
    },

    loadProds () {
        return Api.get('/products')
    }

}
Errol Boneo
  • 57
  • 3
  • 8
  • Looks like parameters mismatch. You pass "props" but use "id" in `async showProd(props)` – Dmitry Jun 17 '20 at 17:53
  • Sorry thats just typo of me figuring it out but still it doesn't work, also in dev tool in network tab this is the value of the id "%7Bid%7D" instead of the number value of "id" – Errol Boneo Jun 17 '20 at 17:58

1 Answers1

0

First make sure your API call is correct:

export default {
    showProd(id) { // async not needed, axios returns promise
        return axios.get('/products/' + id)
    },

    loadProds () {
        return axios.get('/products')
    }
}

You can than call these functions:

showProd (id) {
   Products.showProd(id).then((response) => { // Note the id in the call
     console.log(response.data.product_name) // Use the response object
   })
   .catch((error) => {
     alert(error)
   })
Maarten Veerman
  • 1,546
  • 1
  • 8
  • 10
  • Oh my god it works man I can't believe that this " + " is all I'm missing I've been burning my eyebrows all night, thanks anyways I'll solve this question with your answer and thanks for giving time for this question you're an angel – Errol Boneo Jun 17 '20 at 22:26
  • One last question how to show this to an input?I have a tried assigning the response to property show1prod and tried calling the data like show1prod.product_name I assume the second property is the name field in the database, what is the proper way to show this in the template? like binding this? – Errol Boneo Jun 17 '20 at 22:42