Currently, I am developing a system to facilitate the management of orders at a shipping station. Although I have successfully implemented the initial changes and most of the functionality, I am encountering an issue where one component fails to update another despite confirming that the data is being updated.
Inserting some code snippet now
./store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
greenboard :{
station: 1,
incomplete_orders:[],
complete_orders:[],
},
yellowboard:{
incomplete_orders:[],
complete_orders:[],
},
dashboard:{
},
},
getters: {
greenIncomplete: state => {
return state.greenboard.incomplete_orders;
},
greenComplete: state => {
return state.greenboard.complete_orders;
},
greenStation: state => {
return state.greenboard.station;
}
},
mutations: {
updateGreenOrders (state,payload){
state.greenboard.incomplete_orders = payload.incomplete_orders;
state.greenboard.complete_orders = payload.complete_orders;
},
updateGreenStation (state,payload){
Vue.delete(state.greenboard, 'station');
Vue.set(state.greenboard, 'station', payload.station);
console.log(state.greenboard)
}
},
actions: {}
});
/app.js
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
require('./bootstrap');
window.Vue = require('vue');
/**
* The following block of code may be used to automatically register your
* Vue components. It will recursively scan this directory for the Vue
* components and automatically register them with their "basename".
*
* Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
*/
// const files = require.context('./', true, /\.vue$/i)
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default))
Vue.component('example-component', require('./components/ExampleComponent.vue').default);
Vue.component('green-orders', require('./components/GreenOrders.vue').default);
Vue.component('stations-nav', require('./components/StationsNav.vue').default);
Vue.component('green-board', require('./components/GreenBoard.vue').default);
Vue.component('order-card', require('./components/OrderCard.vue').default);
/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
import store from "./store";
const app = new Vue({
store,
el: '#app',
});
StationsNav.vue
<template>
...
</script>
GreenOrders.vue
<template>
...
</script>
GreenBoard.vue
<template>
...
</script>
For a visual representation of the rendered code, refer to this screenshot https://i.stack.imgur.com/HXTho.jpg
After selecting the second station and updating the store in index.js, clicking the "button" word logs out the correct station. However, the orders do not get updated based on the selected station. Instead, they continue to display orders from the default station. I believe I might be overlooking something as a newcomer to VUE, but familiar with JavaScript. Watchers or actions in Vuex could be the missing link, but I am open to any guidance. Thank you for your assistance in advance.