Currently, I have a code snippet that displays a list of years. It seems to me that this code is a bit excessive, and I believe that implementing a computed property for validYears would streamline the code and eliminate the need for unnecessary watchers. However, I am struggling to understand how to convert this into a computed property. If anyone could provide an example of how I can create a computed property for valid years while achieving the same result, I would greatly appreciate it.
onBeforeMount(calculateDateRange)
watch(() => props.earliestDate, (newValue, prevValue) => {
calculateDateRange();
});
watch(() => props.latestDate, (newValue, prevValue) => {
calculateDateRange()
});
const validYears = ref([])
function calculateDateRange () {
for(let year = props.latestDate; year >= props.earliestDate; year--){
validYears.value.push(year)
}
}
I opted not to include the remaining code to avoid cluttering the question. In this component, I have a set of props that dictate the values in my for loop.