[Vuejs]-ElementUI: How to use <el-table> to traverse data which in a database

0👍

el-table is a component itself and will traverse the data you pass internally.
You have to pass an array of objects to it, so it will iterate it automatically.

Please refer to the docs for examples here

0👍

You need to this like this for example:

    <template>
<div>
  <el-table
    :data="users"
    style="width: 100%">

    <el-table-column
      prop="id"
      label="ID"
      width="180">
    </el-table-column>

    <el-table-column
      prop="name"
      label="Name"
      width="180">
    </el-table-column>

  </el-table>
</div>
</template>

<script>
export default {
    data() {
        return{
            users: [
                {
                    id: 0,
                    name: 'Name 1'
                },
                {
                    id: 1,
                    name: 'Name 2'
                },
                {
                    id: 2,
                    name: 'Name 3'
                },
                {
                    id: 3,
                    name: 'Name 4'
                },
            ],
        }
    },
    
}
</script>

Leave a comment