Axios Vue Js:如何获取此对象的值以在 api 获取请求 url 中显示

Axios Vue Js: How to get the value of this object to show in api get request url

这是我的 vue 文件,它接受来自 table 的 id。这有效,我可以从 table 行

中获取数据 ID
  showProd (id) {
   Products.showProd().then((response) => {
     console.log(show1prod.product_name)
   })
   .catch((error) => {
     alert(error)
   })

这是我的配置文件,用于调用 axios.get 我可以到达后端但不生成查询,因为这个 url/api 发送了一个我认为不是 ID 号的对象

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

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

}

首先确保您的 API 调用正确:

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

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

您可以调用这些函数:

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)
   })