If I try this .$session.get(SessionKeys.Cart)
in my component like this :
<template>
...
</template>
<script>
...
export default {
...
methods: {
add(item) {
console.log(this.$session.get(SessionKeys.Cart)
...
}
}
}
</script>
It works. I success get session cart
But if I try it in the my vuex store like this :
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
}
There exist error : Uncaught TypeError: Cannot read property 'get' of undefined
How can I solve this error?
this.$session
is a Vue plugin, you can't access it from Vuex. Pass yoursession
toaddToCart
action, you can use it from there. – Quoth