반응형
vuex mapState 내의 vue 메서드에 액세스
vuex mapState 내에서 데이터를 계산하는 동안 나는 중요한 작업을 수행해야 한다.나는 이 방법을 vue 메소드라고 불러야 한다.countAlerts
데이터가 변경될 때마다 계산된 속성이 해당 방법을 호출해야 하지만this
Insight vuex mapState를 사용할 때 스코프에는 vue 메서드가 없다.
export default {
name: "Alerts",
methods: {
countAlerts(data, period) {
/// DO SOMETHING, THEN RETURN DATA
return data;
}
},
computed: {
...mapState({
foundation: state => state.insights.foundation,
insights: state => {
return state.insights.list.filter(al => {
switch (state.insights.foundation.period) {
case "daily":
// ====>> NEED TO CALL METHOD HERE <<=====
al = this.countAlerts(al, "daily");
if (
al.threeDayUp ||
al.threeDayDown ||
al.greatDayUp ||
al.greatDayDown
) {
return al;
}
break;
/// MORE CODE ABOVE
}
});
}
})
}
};
this
계산된 소품을 함수로 정의할 때 구성요소의 콘텍스에 바인딩된다.
문서에서:
// to access local state with `this`, a normal function must be used countPlusLocalState (state) { return state.count + this.localCount }
참조URL: https://stackoverflow.com/questions/53903605/access-vue-method-within-vuex-mapstate
반응형
'Programing' 카테고리의 다른 글
npm 패키지에서 가져온 vue 구성 요소를 확장하는 방법 (0) | 2022.04.11 |
---|---|
v-select에 원시 html 표시 (0) | 2022.04.11 |
Vuex 및 FIrebase를 사용하여 여러 이미지를 저장하십시오.(이미지가 업로드될 때까지 대기) (0) | 2022.04.11 |
SASS가 포함된 Webpack-simple + vue-cli - 컴파일할 수 없는가? (0) | 2022.04.11 |
vue 클래스 구성 요소에서 $bvToast에 액세스하는 방법 (0) | 2022.04.11 |