gpt4 book ai didi

javascript - vue w/axios 应该使用从另一个 get-request 检索的变量进行 get-request

转载 作者:行者123 更新时间:2023-12-03 02:21:40 26 4
gpt4 key购买 nike

在构建包含名为 fabmoment 的 3D 打印信息的组件时,我成功地使用 $route.params 填充了作者对象和 fabmoment 对象的信息,像这样:

<script>
import SingleSummarized from './SingleSummarized'
// import Comments from '@/components/Comments/Multiple'
export default {
name: 'Single',
data () {
return {
author: null,
fabmoment: null,
tempLicenseID: null,
license: null
}
},
created () {
this.$http.get(`/users/${this.$route.params.author_id}`)
.then(request => { this.author = request.data })
.catch(() => { alert('Something went wrong when trying to retrieve this user!') })
this.$http.get(`/users/${this.$route.params.author_id}/fabmoments/${this.$route.params.fabmoment_id}`)
.then(request => { this.fabmoment = request.data })
.catch(() => { alert('Something went wrong when trying to retrieve the fabmoment attribute data!') })
this.$http.get(`/licenses/${this.fabmoment.license_id`)
.then(request => { this.license = request.data })
.catch(() => { alert('Something went wrong when trying to retrieve the license!') })
},
components: {
SingleSummarized
// Comments
}
}
</script>

在创建的部分中,您可以看到我还尝试使用 this.fabmoment.license_id 检索 fabmoment 的许可证。它在这条线上失败了。

tempLicenseID 是一个想法吗?因为我怀疑 this.fabmoment 尚不可用。我将如何使用它来使请求起作用?或者还有其他更明智的解决方案吗?

最佳答案

您必须在检索 fabmoment 对象后请求许可证:

this.$http.get(`/users/${this.$route.params.author_id}/fabmoments/${this.$route.params.fabmoment_id}`)
.then(request => { return this.fabmoment = request.data })
.then( fabmoment => this.$http.get(`/licenses/${fabmoment.license_id`)
.then(request => { this.license = request.data })
.catch(() => { alert('Something went wrong when trying to retrieve the fabmoment attribute data!') })

关于javascript - vue w/axios 应该使用从另一个 get-request 检索的变量进行 get-request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49130242/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com