【发布时间】:2020-12-23 12:24:29
【问题描述】:
我正在为在线食品订购页面制作仪表板。作为一项功能,我需要显示每天的总订单销售额,当用户单击特定月份时按付款方式分类。 我能够获得当月的订单以及每个订单的付款方式和订单日期,但我无法在 Vanilla Js 或 Vue 中生成实际功能。
下面的图片显示了我尝试过的以及我需要实现的目标。 请有任何建议。
Vue 代码
var app = new Vue({
el: '#app',
data: {
orders: [],
},
mounted: function() {
// Call the API the first time
this.refreshData()
},
computed: {
totals: function () {
return this.orders.reduce((acc, item) => {
const date = item.date.split('T')[0]
let dayTotal = acc.find(total => total.date === date)
if (!dayTotal) {
dayTotal = {
date,
}
acc.push(dayTotal)
}
dayTotal[item.method] = dayTotal[item.method] ? dayTotal[item.method] + item.total : item.total
return acc
}, [])
}
},
methods: {
// Extract refresh logic into a method
refreshData () {
axios.get('https://staging.testing/wp-json/wc/v3/orders?status=completed,processing&per_page=100&consumer_key=123&consumer_secret=456', {
params: {
after: convertdate,
before: convertbeforedate,
}
})
.then(response => {
this.orders = response.data;
console.log(response);
});
}
}
});
【问题讨论】:
标签: javascript html vue.js