1

I'm a vue.js beginner. I want to get data from app.js using v-for in html and show it in separate divs. I want to add an independent background and an independent text for each todo.

var example = new Vue({
    el:"#example",
    data: {
        todos : [
            {id:1 , name: "ŞEHİR MERKEZİ"},
            {id:2 , name: "HÜDAİ KAPLICA"},
            {id:3 , name: "AFYONKARAHİSAR"}
            
        ]
    }
})
<div class="container" id="example">
      <div class="row">
        <div class="col-lg-6">
          <div class="flip flip-vertical">
            <div
              class="front"
              style="background: url(./static/images/sandıklı.jpg)">
              <h1 class="text-shadow" >
                <div class="hborder"  v-for="todo in todos" :key="todo">
                  {{todo.name}}
                </div>
              </h1>
            </div>
            <div class="back">
              <h4>ŞEHİR MERKEZİ GÜZERGAHINI ONAYLIYOR MUSUNUZ ?</h4>
              <button type="button" class="btn btn-primary btn-lg">EVET</button>
              <button type="button" class="btn btn-danger btn-lg">HAYIR</button>
            </div>
          </div>
        </div>
      </div>
    </div>
    <script src="./static/js/[email protected]"></script>
    <script src="./static/js/app.js"></script>

0

1 Answer 1

1

what you could do is add the background color and description to the todos object. Also I made a little change in your data function.

var example = new Vue({
    el:"#example",
    data() {
      return {
        todos : [
            {id:1 , name: "ŞEHİR MERKEZİ", bg: '#FFF', desc: 'desc1'},
            {id:2 , name: "HÜDAİ KAPLICA", bg: '#ff0000', desc: 'desc2'},
            {id:3 , name: "AFYONKARAHİSAR", bg: '#cecece', desc: 'desc3'}
            
        ]
      }
    }
})
<div class="container" id="example">
      <div class="row">
        <div class="col-lg-6">
          <div class="flip flip-vertical">
            <div
              class="front"
              style="background: url(./static/images/sandıklı.jpg)">
              <h1 class="text-shadow" >
                <div class="hborder"  v-for="todo in todos" :key="todo" :style="background-color: todo.bg;">
                  {{todo.name}}
                  {{todo.desc}}
                </div>
              </h1>
            </div>
            <div class="back">
              <h4>ŞEHİR MERKEZİ GÜZERGAHINI ONAYLIYOR MUSUNUZ ?</h4>
              <button type="button" class="btn btn-primary btn-lg">EVET</button>
              <button type="button" class="btn btn-danger btn-lg">HAYIR</button>
            </div>
          </div>
        </div>
      </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>

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.