【发布时间】:2020-04-07 08:14:58
【问题描述】:
我正在开发一个vue-应用程序,其中有一个用于驾驶执照的组件。
我有以下几点:
data() {
return {
custom_licenses: [],
basic_licenses: []
}
}
在我的方法中,我有这个:
regular_licenses() {
this.$store.dispatch("license/read").then(response => {
response.licenses.map((license, key) => {
// PUSH LICENSES WITH TYPE 'BASIC' TO this.basic_licenses
// PUSH LICENSES WITH TYPE 'CUSTOM' TO this.custom_licenses
});
});
},
在我的 created() 中我有这个:
created() {
this.regular_licenses()
}
来自我的调度的响应,返回:
licenses:
[
{
id: 1,
type: 'basic',
name: 'AMa'
},
{
id: 2,
type: 'basic',
name: 'A2'
},
{
id: 3,
type: 'basic',
name: 'C'
},
{
id: 4,
type: 'custom',
name: 'C1'
},
{
id: 5,
type: 'custom',
name: 'D'
},
and so on...
]
现在我想循环遍历数组并根据type-attribute 将它们分开或推送到custom_licenses 和basic_licenses - 我该如何实现?
【问题讨论】:
标签: javascript arrays vue.js vuejs2