The issue with the current implementation is that the setter is trying to set the value of the computed property itself, which leads to an infinite loop and eventually a "Maximum call stack size exceeded" error.
To fix this, we can create a separate data property to hold the filtered list, and update it in the setter of the computed property. Here's an example implementation:
data() {
return {
filteredList: [],
};
},
computed: {
first_rows: {
get() {
const ids = this.column_types.filter(x => ['answer', 'points', 'relation'].includes(x.name)).map(x => x.id);
return this.sheet.survey_excel_columns.filter(x => !ids.includes(x.survey_excel_column_type_id));
},
set(newValue) {
const orderedIds = newValue.map(x => x.key);
this.filteredList = this.sheet.survey_excel_columns.filter(x => !ids.includes(x.survey_excel_column_type_id)).sort((a, b) => {
const aIndex = orderedIds.indexOf(a.key);
const bIndex = orderedIds.indexOf(b.key);
return aIndex - bIndex;
});
},
},
},
In this implementation, we create a new data property called filteredList to hold the filtered list. In the setter of the first_rows computed property, we sort the original list based on the order of the keys in newValue, and update filteredList with the sorted list.
Note that we also renamed ordered_ids to orderedIds to follow JavaScript naming conventions.