Search code examples
laravelvue.jsv-for

Need to go through 2 objects at the same time with VUEJS


I just want to throught POSTS and USERINFO at the same pace, in a way that in show the right user avatar for a given post

Objects

   posts : {!! $posts !!},
   userinfo : {!! $userinfo !!}, 

Template

< v-cloak v-for="post in posts">
  <div v-bind:style="{ backgroundImage: 'url(' + post.picture + ')' }">
<a href="{{-- url("#" v-bind:style="{ backgroundImage: 'url(' + userinfo.avatar + ')' }"></a>
</div>

Dont know how... basicly...


Solution

  • The correct way (IMHO) is to provide the data to the template in a correct way, so the template just loops through the data the least amount of time.

    To support that a computed value may be the easiest way to implement.

    You can create a complex loop using js in you computed value, and then you reduce any complex logic in the template. This may also reduce the number of renders or re-computations needed if other parts of the component or template are changing.

    other options are to update data.variable using a watch or from an api callback