0
I have a method where I need to take the number of each table, but the return is always the length of the property and not its value. If I leave only one table the method correctly returns the value of the property, but if I add more tables in the object, the return will be the length of tables that exist.
let app = new Vue({
el: '#app',
data: {
tituloApp: 'Acompanhamento de mesas',
escolhaMesa: 'Escolher a mesa',
mesas = {
idMesa: {
consumo: [
{
nome: 'suco maracujá',
quantidade: 1,
valor: 5.50
},
{
nome: 'guaraná coca-cola',
quantidade: 1,
valor: 3.00
},
{
nome: 'feijoada',
quantidade: 2,
valor: 12.00
}
],
numMesa: 1
},
idMesa: {
consumo: [
{
nome: 'água',
quantidade: 2,
valor: 2.50
},
{
nome: 'guaraná fanta-uva',
quantidade: 2,
valor: 3.00
},
{
nome: 'porção de frios',
quantidade: 2,
valor: 23.50
}
],
numMesa: 2
}
},
methods: {
MostraMesa: function(mesa) {
let idMesa = this.mesas.idMesa.numMesa; // retorna o length
}
}
})
HTML:
<div id="mostra-mesa">
<div>
<p>{{ produtos }}</p>
<ul>
<li v-for="nomes in mesas">{{ nomes.consumo.nome}}</li>
</ul>
</div>
<div>
<p>{{ quantidade }}</p>
<ul>
<li v-for="consumos in mesas">{{ consumos.consumo.quantidade }}</li>
</ul>
</div>
<div>
<p>{{ vlrUnit }}</p>
<ul>
<li v-for="valores in mesas">{{ valores.consumo.valor }}</li>
</ul>
</div>
<div>
<p>{{ vlrTotal }}
<input type="number" readonly v-model="vlrConta" @click="MostraMesa">
</p>
</div>
</div>
Thanks for the help Jorge. I edited the question, I had forgotten to pass the function within the method. I will remake my object as you showed and test to see.
– LeAndrade
If it works please confirm the answer
– Jorge Costa
Man then, I’m not getting anything else in this structure there, as I do for example to list the property name of a table on a
v-for
?– LeAndrade
<li v-for="table in tables"> {{ table.numMesa }} </li>
– Jorge Costa
Rsrsr... sorry there man I’m new with Vue, how do I catch name within consumptions made:
<li v-for="nomes in mesas"> {{ nomes.consumos.nome }} </li>
but brings nothing, only the Bullets of the read.– LeAndrade
It has two arrays tables and consumes have to make two for one for each array and one within the other
– Jorge Costa
So if you want to screw me right Jorge kkkkkk.... I don’t know how you do it, in html you can do it, go inside? In Vue’s documentation I saw nothing like it.
– LeAndrade
See addition in response
– Jorge Costa
I’ll edit my question and add html tbm, because that’s where I’m getting lost, in the html structure.
– LeAndrade