我有一个普通的 单文件组件,它既有一个计算属性,也有一些方法:
<template>...</template>
<script>
...
export default {
props: ['matches'],
data: function() {...} // No problem with these
computed: {
formattedMatches: function () {
let formatted = [];
this.matches.forEach(function($match, $i, $arr) {
formatted[$i] = $match[0];
};
});
return formatted;
}
...
methods: {
getData: function() {
return this.formattedMatches();
},
...
}
}
<script>
当我尝试从方法中访问this.formattedMatches()
时,出现了[Vue warn]: Error in render: "TypeError: this.formattedMatches is not a function"
的错误提示。
请问达到我的目的的正确方法是什么?谢谢。
this.formattedMatches()
更改为this.formattedMatches
。 - Sphinx