0

Following a Vue tutorial, I ran into a problem. The code is same, but I can't display template using v:for loop. Here is my code

Vue.component('accordion', {
  template: `<p>Hello</p>`
});

new Vue({
  el: '#app',
  data: {
    items: [{
        title: 'Title 1',
        description: 'Description for tab 1.'
      },
      {
        title: 'Title 2',
        description: 'Description for tab 2.'
      },
      {
        title: 'Title 3',
        description: 'Description for tab 3.'
      },
    ]
  },
});
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue from Scratch</title>
  </head>
  <body>
    <div id="app">
      <accordion v:for="item in items"></accordion>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  </body>
</html>

The template should be displayed three times (3x Hello), but I only get one Hello.

0

1 Answer 1

2

You have a syntax problem with v-for. This is the correct syntax:

<ul id="example-1">
  <li v-for="item in items" :key="item.message">
    {{ item.message }}
  </li>
</ul>
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.