【问题标题】:How do I get the id of the created order如何获取已创建订单的 id
【发布时间】:2022-01-14 08:32:47
【问题描述】:

我正在使用带有 Nuxt 的 Strapi,并且我想重定向到它在成功将订单发布到 Strapi 后创建的新订单。我正在寻找的是相当于 PHP 世界中的mysql_insert_id()

代码示例

try {
    const neworder = await this.$strapi.$orders.create(this.neworder)
    console.log(neworder)
    if(neworder !== null) {
        this.$router.push({ name:'order-id', params: neworder.id })
    }
} catch (error) {
    this.error = error
}

我可以在控制台日志中看到新的 id:

如何访问返回的 id 并将其传递给 this.$router.push 的参数?我尝试使用与控制台上显示的相同的“id”,但没有运气。

【问题讨论】:

    标签: javascript nuxt.js strapi nuxt-strapi


    【解决方案1】:

    我想通了。我将保持打开状态以防它对其他人有所帮助。

    redirect ($router.push) 应该是这样的:

    this.$router.push({ name:'order-id', params: {id: neworder.id }})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-29
      • 2014-03-12
      • 2017-08-28
      • 1970-01-01
      • 1970-01-01
      • 2016-10-19
      • 2017-08-26
      • 2020-05-08
      相关资源
      最近更新 更多