In event.agents
I've plain text ID's stored, which I want to fetch do get the specific data. I wrote a computed function to fetch the data, but my backend server always crashes through this way.
CastError
Cast to ObjectId failed for value "[object Object]" (type string) at path "_id" for model "User"
So, I guess I have to work with Promise somehow. But I don't know how.
The idea is to display the required agent data e.g. like this:
<p>{{ getAgent(agent).first_name }}</p>
Is it even possible like that?
<div v-for="agent in event.agents" :key="agent.id">
<p>{{ getAgent(agent) }}</p>
</div>
computed: {
getAgent(agentID) {
const agent = this.fetchAgentData(agentID)
return agent
}
}
// I tried it with async/await, but eslint tells me 'no-async-in-computed-properties'
async fetchAgentData(agentID) {
try {
const agent = await this.$axios.$get(`/api/get-specific-agent/${agentID}`)
if (agent.success) {
return agent.data
}
} catch (err) {
console.log(err)
}
},