我的目标是将要与v-for
循环的对象的键名存储在组件数据对象内的数组中。我已经看到其他人将其作为道具传递给一个单独的组件,但我需要将其存储在运行v-for循环的同一组件中。
<div v-for="(fieldData, fieldName, index) in fieldset.fields" :key="`c-form__field--${index + 1}`"></div>
我需要将每个fieldName
放入我的数据对象中的名为currentFields
的数组中。
答案 0 :(得分:0)
您可以添加一个computed method。
computed: {
// a computed getter
currentFields:
let arr = [];
this.fieldset.forEach(fields => {
arr.push(//whatever you need to save)
});
return arr;
}
}