I am making a dashboard app where someone can add any widget in any order to their dashboard. It's all working but Im trying to kill some technical debt and clean up.
For simplicity, lets say a dashboard can have 2 widgets (Clock and Weather). These widgets need some data from the dashboard record. The widgets can be in any order on the page.
Im including them like so.
data () {
return {
widget1: 'Clock',
widget2: 'Weather',
widgetData: {
weather: {
long: '12.23.34',
lat: '23.34.45'
},
Clock: {
timeFormat: '24Hour',
dateFormat: 'US'
}
}
}
}
Then in the HTML
<component v-bind:is="this.widget1" :widgetData="widgetData"></component>
<component v-bind:is="this.widget2" :widgetData="widgetData"></component>
Now what I want to do is
<!-- if this.widget1 is Clock then :widgetData should equals widgetData.Clock -->
<component v-bind:is="this.widget1" :widgetData="widgetData.this.widget1"></component>
<!-- if this.widget2 is Weather then :widgetData should equals widgetData.Weather -->
<component v-bind:is="this.widget2" :widgetData="widgetData.this.widget2"></component>
so that the this.widget1 will populate both the :is and drill down into the :widgetData object so Im not passing the whole object to each component
My example take into consideration only 2 widgets but in reality a simple dashboard can have up to 9.
I've tried pretty much every thing such as
:widgetData="widgetData.{{this.widget1}}"
:widgetData="widgetData.${this.widget1}"
etc.
Any ideas?