VueJS How can I use computed property with v-for

后端 未结 4 1936
天命终不由人
天命终不由人 2020-11-29 21:12

How can I use computed property in lists. I am using VueJS v2.0.2.

Here\'s the HTML:

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 21:13

    You can't create a computed property for each iteration. Ideally, each of those items would be their own component so each one can have its own fullName computed property.

    What you can do, if you don't want to create a user component, is use a method instead. You can move fullName right from the computed property to methods, then you can use it like:

    {{ fullName(user) }}
    

    Also, side note, if you find yourself needing to pass an arguments to a computed you likely want a method instead.

提交回复
热议问题