반응형
Vue.js를 사용하여 단일 파일 구성 요소의 메서드에서 계산된 속성에 액세스하는 방법
계산된 속성과 몇 가지 메서드를 모두 가진 일반적인 단일 파일 구성 요소가 있습니다.
<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" .
원하는 것을 달성하는 올바른 방법은 무엇입니까?잘 부탁드립니다.
다음과 같은 계산된 속성에 액세스할 수 있습니다.property, 과는 다릅니다.method:
// correct
console.log(this.myProperty);
// wrong
console.log(this.myProperty());
주의: 파라세시스를 사용하는 방법으로 취급하는 경우()그것은 다음과 같은 오류를 던질 것이다.Error in v-on handler: "TypeError: this.myProperty is not a function".
언급URL : https://stackoverflow.com/questions/52411711/how-to-access-a-computed-property-from-a-method-in-a-single-file-component-with
반응형
'source' 카테고리의 다른 글
| Java: System.console()에서 입력을 받는 방법 (0) | 2022.08.14 |
|---|---|
| CMake에서의 디버깅과 릴리스 (0) | 2022.08.14 |
| /proc/ 파일을 해석해도 안전한가요? (0) | 2022.08.14 |
| C 어레이를 반복합니다. (0) | 2022.08.14 |
| Enter 키를 누르면 vuejs의 버튼을 클릭합니다. (0) | 2022.08.14 |