I have a situation where a "v-for" calls, for each iteration, 2 methods. They are called when user press a button.
Users tell to the component the number (itemsDrawn property) of iterations that the v-for will operate.
"itemsDrawn" property can vary from 0 to 4. v-for draws bootstrap cards in each iteration (can be 0 to 4)
These methods (method A and B) return an integer/code or a string (I can decide) and inside the template I need to display some message based on code (type of data) provided for each function.
So, based on theses codes I can select which text I will display in the UI.
The code snipped is like so:
<div
class="card text-center mt-5"
style="width: 18rem"
v-for="(item, index) in itemsDrawn"
:key="index"
>
<div class="card-header">Item: {{ item }} - {{ methodA() }}</div>
<div class="card-body">
<h5 class="card-title">{{ methodB() }}</h5>
<p class="card-text">
'This is the message based on both methodA() and methodB()'
'I NEED TO CALL A METHOD HERE
</p>
</div>
</div>
Methods
methods: {
methodA(){
return this.workItemsTypes[this.randomNumber(0,9)];
},
methodB() {
return this.classesOfServices[this.randomNumber(0,7)];
},
},
The output is like so:
Look at the first column of the output, "Melhoria" in the card header and "Padrão" in the card body should display a personalized message; the same occurs for each card.
If I call these methods inside p-card-text they will give me others values. Thus, this would be 4 calls, 2 for each method.
So, how can I call them only once, hold their outputs and show a message based on their data?
How to keep these 2 values in each method called and use them later?