2

I want to use the bootstrap cards with Vue dynamically. With Bootstrap Vue, to create a card I can do the following.

      <b-card title="Title" img-src="https://placekitten.com/500/350" img-alt="Image" img-top>
        <b-card-text>
          {{getBlogOfType("Vue")}}
        </b-card-text>
        <b-card-text class="small text-muted">Last updated 3 mins ago</b-card-text>
      </b-card>

What I want to be able to do is create the number of cards based on the number of blogs I have from a database. I have my project linked to Firebase and I am able to access the content. I have written a method "getBlogOfType(param)" to get the blog from firebase. As shown above I can call the method multiple times to get the blog I want, but how can I achieve this without manually creating a separate card every time?

2
  • Do you have the blog data stored in a variable? Commented Jun 1, 2019 at 18:28
  • @Omari Yes I do Commented Jun 1, 2019 at 18:30

1 Answer 1

2

Once you have a variable set aside for the data, for example var posts = [...];, you can use VueJs's v-for as follows:

  <b-card v-for="post in posts" title="Title" img-src="https://placekitten.com/500/350" img-alt="Image" img-top>
    <b-card-text>
      {{getBlogOfType("Vue")}}
    </b-card-text>
    <b-card-text class="small text-muted">Last updated 3 mins ago</b-card-text>
  </b-card>

And use access the values of each element via the post object (post.title).

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.