Возможно, очевидный, но у меня есть однофайловый компонент Vue вроде этого:
<template>
...
</template>
<script>
export default {
props: [ 'matches', 'results' ],
computed: {
formattedMatches: function () {
let rows = [];
this.matches.forEach(function($match, $i) {
rows[$i] = {
id: $i + 1,
title: $match[0] + ' ' + $match[1]
};
});
return rows;
},
formattedResults: function () {
let rows = [];
this.results.forEach(function($resultRow, $i) {
rows[$i] = {
id: $i + 1,
title: this.formattedMatches[$i]
// Error in render: "TypeError: Cannot read property 'formattedMatches' of undefined"
};
});
return rows;
},
...
</script>
Ошибка появляется также, если я пытаюсь использовать this.matches
, а не только this.formattedMatches
. Я полагаю, что это вопрос переменных в пределах классов и методов, но я даже не знаю, есть ли другой лучший способ или шаблон для достижения того же поведения.
Любые идеи? Заранее спасибо.