반응형
vuex 저장소에서 "Uncaught TypeError: 정의되지 않은 속성 'get'을 읽을 수 없음"을 어떻게 해결할 수 있습니까?
내가 노력하면this .$session.get(SessionKeys.Cart)
다음과 같은 내 구성요소에서:
<template>
...
</template>
<script>
...
export default {
...
methods: {
add(item) {
console.log(this.$session.get(SessionKeys.Cart)
...
}
}
}
</script>
그건 효과가 있다.세션 카트 가져오기 성공
하지만 이렇게 myvuex 스토어에서 시도해보면,
import { set } from 'vue'
// initial state
const state = {
list: {}
}
// getters
const getters = {
list: state => state.list
}
// actions
const actions = {
addToCart ({ dispatch,commit,state },{data})
{
console.log(this.$session.get(SessionKeys.Cart))
...
}
}
// mutations
const mutations = {
...
}
export default {
state,
getters,
actions,
mutations
}
오류가 있습니다.Uncaught TypeError: Cannot read property 'get' of undefined
이 오류를 어떻게 해결할 수 있습니까?
구성 요소를 전달할 수 있습니다.this
페이로드를 사용한 디스패치라고 하는 디스패치 기능으로 이동합니다.이와 같이:
<template>
...
</template>
<script>
...
export default {
...
methods: {
this.$store.dispatch('addToCart', { data: {}, ctx: this })
// add(item) {
// console.log(this.$session.get(SessionKeys.Cart)
// ...
//}
}
}
</script>
import { set } from 'vue'
// initial state
const state = {
list: {}
}
// getters
const getters = {
list: state => state.list
}
// actions
const actions = {
addToCart ({ dispatch, commit, state }, { data, ctx })
{
console.log(ctx.$session.get(SessionKeys.Cart))
...
}
}
// mutations
const mutations = {
...
}
export default {
state,
getters,
actions,
mutations
}
당신은 이걸 할 수 있다.
import Vue from 'vue’
const session = Vue.prototype.$session;
당신의 가게의 맨 위에 그리고 당신의 행동 방식에.
console.log(session.get(SessionKeys.Cart))
이것은 효과가 있을 것입니다.
언급URL : https://stackoverflow.com/questions/52529345/how-can-i-solve-uncaught-typeerror-cannot-read-property-get-of-undefined-in
반응형
'it-source' 카테고리의 다른 글
SQL: AVG(NULL 값 포함) (0) | 2023.06.20 |
---|---|
Spring Context @Configuration에서 void 설정 방법 실행 (0) | 2023.06.20 |
점이 너무 많은 산점도 (0) | 2023.06.20 |
Docker compose에서 명령을 한 번 실행하는 방법 (0) | 2023.06.20 |
Panda DataFrame에서 열 지도 만들기 (0) | 2023.06.20 |