To access the video state data, simply utilize the mapState
helper. Here's an example implementation in your Video
component:
import { mapState } from 'vuex'
export default {
name: 'Video',
computed: mapState(['assetVideo'])
}
You can then use this.assetVideo
within your component's methods and assetVideo
in its template. This setup will reactively update based on changes in the store.
When it comes to setting the value, mutations are essential. Here is a basic example of how you can define a mutation:
const store = new Vuex.Store({
strict: true,
state: {
assetVideo: {}
},
mutations: {
setVideoAsset: (state, assetVideo) => (state.assetVideo = assetVideo)
}
}
Then, in your components, you can trigger this mutation like so:
methods: {
selectVideo (video) {
this.$store.commit('setVideoAsset', video)
}
}