Is there a way to execute a method inside a v-for loop in my Vue component? Take a look at this example:
<div v-for="(item,index) in list">
<p>{{myCustomMethod(item,index)}}</p>
</div>
However, when I try to run the method, the paragraph tag ends up being empty. Here is the method along with an axios call:
myCustomMethod: function(item, index) {
axios.get('/fetchData')
.then((response)=> {
alert(response.data);
return response.data;
})
.catch(function (error) {
console.error(error);
});
},
}
Interestingly, when I use
alert( SomethingWithItemAndIndex)
, the expected output is displayed in the browser. But as soon as I remove the axios call, the method seems to work just fine.
Any suggestions or tips would be greatly appreciated. Thank you!