PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 2, 2022

[FIXED] how to build dynamic table with vue?

 August 02, 2022     html-table, vue-component, vuejs2     No comments   

Issue

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?


Solution

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>



Answered By - Terry
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,205,719

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing