2👍
✅
Yes, you can use this.$store.commit('YOURCOMMITNAME', payload)
in the created
, beforeMount
& mounted
lifecycle hook of any component.
EDIT: I am not sure about your use case but if you need to use this
, you should try fat arrow function. Something like
objectLayer.on("layeradd", e => {
console.log(e, this.$store.getters.test);
this.$store.commit('setData', payload);
});
OR may be define the function first OR try .bind(this)
Source:stackexchange.com