I am currently working on an app that needs to display data fetched from multiple sources based on a condition. The issue I am facing is that the process of fetching, organizing, and returning the data varies depending on the source, sometimes even requiring me to import additional libraries for just one method.
My current setup is similar to the example provided below. However, as my list of data sources continues to expand, I am concerned about scalability. How should I structure the app to accommodate a potentially large number of sources? Any guidance would be greatly appreciated!
<template>
<div>
<h1>{{data.title}}</h1>
<h2>{{data.subtitle}}</h2>
<p>{{data.description}}</p>
</div>
</template>
<script>
export default {
data() {
return {
data: {}
}
},
methods: {
getFetchMethod() {
var i = Math.floor(Math.random() * 3);
if (i == 0) {
this.getData();
} else if (i == 1) {
this.getDataThisWay();
} else if (i == 2) {
this.getDataAnotherWay();
} else {
this.getDataEtc();
};
},
getData() {
this.data = {
'title': 'Foo',
'subtitle': 'Bar',
'description': 'Blah'
};
},
getDataThisWay() {
this.data = {
'title': 'Foo',
'subtitle': 'Bar',
'description': 'Blah'
};
},
getDataAnotherWay() {
this.data = {
'title': 'Foo',
'subtitle': 'Bar',
'description': 'Blah'
};
},
getDataEtc() {
this.data = {
'title': 'Foo',
'subtitle': 'Bar',
'description': 'Blah'
};
}
},
mounted() {
this.getFetchMethod();
}
}
</script>
<style lang="css">
</style>