0

I am looking for a way to send that comment.id in v-for to my userimage in computed property

<template>
    <div>
        <div id="comments" v-for="(comment,i) in allcomments">

            <div id="comment">
                <img class="userimg" :src="userimg" alt="">
            </div>
        </div>


    </div>
</template>

and this is my computed

computed:
            {
                allcomments()
                {
                    return this.$store.getters.comments;
                },
                userimage()
                {

                }
            },

I don't want to do it by methods. I just want to do that by computed

please help me.

Siong Thye Goh
  • 3,518
  • 10
  • 23
  • 31
erfan ahmad
  • 49
  • 1
  • 8
  • Can you share how desired image url should look like? Also you cannot pass parameters to computed properties, so what you desire will not work. For example: https://stackoverflow.com/questions/40522634/can-i-pass-parameters-in-computed-properties-in-vue-js – user8672473 Aug 23 '19 at 22:58

1 Answers1

0

Well, as user8672473 said, it's not really possible. If you insist on using a computed property, you can make this portion of your code into a component:

       <div id="comment">
            <img class="userimg" :src="userimg" alt="">
        </div>

reworked parent component:

<template>
    <div>
        <div id="comments" v-for="(comment,i) in allcomments">

            <comment-component :comment="comment">
            </comment-component>
        </div>


    </div>
</template>

And this will be your comment-component:

    <template>
       <div id="comment.id">
           <img class="userImg" :src="userImg" alt="">
       <div>
    </template>

    <script>
    export default {
        props: {
            comment: {
                type: Object
            }
        },
        computed: {
            userImg({ comment }) {
                return comment.id
            }
        }
    }
    </script>
Cathy Ha
  • 1,637
  • 7
  • 17