你好,我的问题是我想添加两个函数,并且我想将其总和放在另一个数组中;我需要将收入作为数组还是将其作为函数就可以了?我还认为,由于该按钮,最好将函数中的 numa 分配为数组。
另外,当我尝试将其表述为 this.functionA+this.functionB
时,结果是,。
基本上,整个想法是我需要计算每个月的收入,所以我添加了一个按钮并制作了数组来解析结果,然后投影它们。
其代码如下:
export default{
name: 'Home',
data(){
return{
FormData: {
revenue:[
{
lollipops:[
{
lolliSold:0,
pricePerLolli:0,
}
],
chocolate:[
{
numchocoSold:0,
pricePerChoco:0,
}
],
numa:0,
oprod:0
}
] }}
computed: {
lolliesSale(){
let SaleArray=[];
this.FormData.revenue.forEach((ItemL, indexL)=>{
SaleArray[indexL]=ItemL.lollipops[0].lolliSold+ItemL.lollipops[0].pricePerLolli;
});
return SaleArray;
},
chocolateSale(){
let choSaleArray=[];
this.FormData.revenue.forEach((ItemC, indexC)=>{
choSaleArray[indexC]=ItemC.chocolate[0].numchocoSold*ItemC.chocolate[0].pricePerChoco;
});
return choSaleArray;
},
numaSupport(){
let numaSuppArray=[];
this.FormData.revenue.forEach((ItemN, indexN)=>{
numaSuppArray[indexN]=ItemN.numa;
});
return numaSuppArray;
},
revenue(){
//return this.<anyfunction>; <- this is ok!!!!
}
最佳答案
好的,那么创建一个数组monthlyRevenues:[], 在每个月底,将totalRevenue压入数组并将totalRevenue设置为零。您可以对商店中的任何商品执行相同的操作。然后对 MonthlyRevenues 中的每个项目使用 v- 并将其显示在页面 {{item}}
上关于javascript - 如何在 javascript-vuejs 中将两个函数的总和放入数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49895402/