Vue.js Use method in v-for Vue.js Use method in v-for vue.js vue.js

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>

  1. add dataBar in data
  2. do myMethod with variable bar in another method newMethod
  3. update dataBar(the axios response) in newMethod
  4. do newMethod in mounted(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:

Vue.js 2: Computed