0

I tried to find the way build table from the following data property:

   data(){
   return {
       headlist: [
    {row: ID},
    {row: Name},
    {row: Title},
    {row: Description },
    {row: Actions }
    ],
    
    }

Template code:

    <table class="table table-bordered">
          <thead>
          <tr>
              <th>ID</th>
              <th>Name</th>
              <th>Title</th>
              <th>Description</th>
              <th>Actions</th>
          </tr>

Now tried to replace to :

           <thead>
           <tr v-repeat="headlist ">
              <th>{{row}}</th>
          </tr>
          </thead>
 

Found example from https://012.vuejs.org/guide/list.html

What is wrong my code?

0

1 Answer 1

2

That's the documentation for the older version of VueJS. You shouldn't be referring to that. Also, you should be using the v-for directive:

<th v-for="(entry, i) in headlist" v-bind:key="i">
  {{ entry.row }}
</th>

Proof-of-concept:

new Vue({
  el: '#app',
  data: function() {
    return {
      headlist: [{
          row: 'ID'
        },
        {
          row: 'Name'
        },
        {
          row: 'Title'
        },
        {
          row: 'Description'
        },
        {
          row: 'Actions'
        }
      ],
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <table class="table table-bordered">
    <thead>
      <tr>
        <th v-for="(entry, i) in headlist" v-bind:key="i">
          {{ entry.row }}
        </th>
      </tr>
    </thead>
  </table>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, first I did not get that code work, but problem was line under my Array. bodylist: [skillset.id, skillset.name, skillset.title, skillset.body, <- this was problem. Your code work perfectly.

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.