My Background:
- I have expertise in Python and Vue development, with a history of using Vue dating back to 2016.
- One of my clients operates a business focused on weight loss and meal planning: clients pay her for weekly single-page PDF menus that outline their daily breakfast, lunch, and dinner choices. (example menu)
- Each meal is detailed with a list of ingredients.
- Currently, she creates these menus using Excel, and I have been tasked with replicating and expanding this functionality into a Python/Vue application.
- The application I am developing for her includes multiple "pages" or top-level components where she can manage clients, ingredients, recipes, as well as define meals for each day of the week through a complex UI component called
WeeklyMenu.vue
. WeeklyMenu.vue
consists of seven child components calledDailyMenu.vue
, one for each day of the week (Monday, Tuesday, etc.).- Each
DailyMenu.vue
component contains fourMeal.vue
components representing the meal types: Breakfast, Lunch, Dinner, and Snacks. - Note: Currently, the data within the
DailyMenu.vue
andMeal.vue
components are self-contained rather than being accessed from a Vuex store.- For example, the ingredient lists for each meal are contained within the
Meal.vue
component'sdata
attribute. This leads to numerous HTTP requests sent to retrieve individual meal data upon page load instead of fetching all data at once through a Vuex action.
- For example, the ingredient lists for each meal are contained within the
The Issue:
- The challenge arises as the client requires features wherein a change in one subcomponent should reflect in another subcomponent.
- Specifically, she wants the app to synchronize changes made to common recipes across different meals of the week. For instance, modifying an ingredient in one meal should update other meals containing the same recipe.
Question:
What would be the best approach to address this scenario? Should I move ingredient data to the Vuex store or consider a hierarchical approach by storing it within the parent WeeklyMenu.vue
component? How should this implementation work efficiently - with separate variables for each meal or a unified object encompassing all meal data?
If utilizing separate variables, passing every meal's ingredients as props to each meal seems inefficient. How can changes in one meal only affect similar meals?
Related Resources:
- Communication between sibling components in VueJs 2.0
- I am exploring the option of elevating ingredient data to the level of the
WeeklyMenu.vue
component following the "Lowest Common Ancestor" approach outlined here and here.
- I am exploring the option of elevating ingredient data to the level of the
Example Scenario:
- Without Vuex: https://codepen.io/NathanWailes/pen/zYBGjME
- Using Vuex: https://codepen.io/NathanWailes/pen/WNxWxWe
- State maintained in Vuex but lacks proper propagation: https://codepen.io/NathanWailes/pen/KKMYNVZ