2

I am making a news website using NYT REST API. I want to add attributes to the components dynamically using the document.getElementsByClassName()

For Example, I want to add a title to my component (the title is a prop actually of type String), I want to add it dynamically using a loop. I have added it normally in the given code snippet, but what if I have 30 components and I have data in an array and I want to give title from that array.

<News_Card class="card" :title='this.all_data[0].title' />

I want this :title='this.all_data[0].title to be added using loop

0

1 Answer 1

3

You could use v-for directive to render the all_data items :

<News_Card class="card" v-for="(item,index) in all_data" 
                    :title='item.title' :key="index" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.