Vue.js Use method in v-for
I dont think you should use myMethod
in v-for
axios is asynchronous
Try to do myMethod
with bar
in another method, get a data newbar
, you can render the newbar
<div v-for="(foo, index) in dataBar"> <p>{{otherSimpleMethod(foo, index)}}</p> </div>
- add
dataBar
in data - do
myMethod
with variablebar
in another methodnewMethod
- update
dataBar
(the axios response) innewMethod
- do
newMethod
inmounted
(I guess you want to do this after page loaded)
Or you can try nextTick
BTW, the title Vue.js Use mounted in v-for
??? maybe Vue.js Use method in v-for
???
You has issue in your code. You missed a quote <div v-for="(foo,index) in bar"> <p>{{myMethod(foo,index)}}</p></div>
Please refer the following jsbin http://jsbin.com/wovavut/edit?html,js,output
I also don't believe you should use a method in the v-for
, but instead use a computed property that applies your method to the unprocessed array of your items that likely sits somewhere in data
: