0
I am trying to render some data in a table using Vuejs. I am making a request with Axios as follows:
export default {
data() {
return {
movimentos: []
};
},
mounted() {
axios.get('urlDaAPIAqui/movimento')
.then((response) => {
console.log(response.data)
this.movimentos = response.data
})
}
}
The data is coming in an Array, but I’m having trouble rendering in the table:
<tr>
<th>Código</th>
<th>Descrição</th>
<th>Tipo</th>
<th>Valor</th>
</tr>
</thead>
<tbody>
<tr v-for="movimento in movimentos">
<td>{{ movimento.mov_codigo }}</td>
<td>{{ }}</td>
<td>{{ }}</td>
<td>{{ }}</td>
</tr>
Returned array:
The data returned from the request are mov_codigo, mov_descricao, mov_tipo and mov_valor, I already tried to use all within td’s and it didn’t work.
Reply from Postman:
{
"movimento": [
{
"mov_codigo": "m01",
"cta_codigo": 1,
"mov_tipo": "D",
"mov_descricao": "Combustivel",
"mov_valor": 154.56
},
I hope someone can help me, thanks in advance.
Ever tried to give a push in moves instead of assigning the value of the?
– LeAndrade
type this.movimentos.push(Sponse.data) ?
– danibrum
Ahan, there you go.
– LeAndrade
I tried it now and it didn’t work, on my console.log the answer is this: {error: false, date: Array(12)} An array of 12 items.
– danibrum
Then you have some problem with the Response. Put the array that is returned there in the question.
– LeAndrade
I’m going to post a picture of what it looks like because it gets bad from picking up the console..
– danibrum
Dude it’s kind of weird that there, if you open the code mov_code has what, inside these parentheses?
– LeAndrade
Guy opens this whole Answer for us to analyze, thinking that the Answer is not an array.
– LeAndrade
@Leandrade opened in Postman, it looks like an object, and inside it has an Array. I’ll put an example.
– danibrum
So, that’s what I suspected, it’s an array of objects, then it changes everything!
– LeAndrade
Hmmm, that’s right. Any suggestions for iterating?
– danibrum
I solved here, I passed Sponse.data.movement and it worked, thank you very much in any personal way!
– danibrum