zoukankan      html  css  js  c++  java
  • elementUI表格显示数据

    elementUI官方文档里的表格数据都是写死的,不是循环来的,现在精简一下。

    1.定义tableData

    tableData: [
            { date: "2010-1-2", name: "嘻嘻", address: "广州天河东圃" },
            { date: "2010-1-2", name: "嘻嘻", address: "广州天河东圃" },
            { date: "2010-1-2", name: "嘻嘻", address: "广州天河东圃" }
          ],

    2.定义tableCol,里面需要包含prop,label,width. 如果没有width属性,那么会占用剩下的宽度

     tableCol: [
            { prop: "date", label: "日期",  180 },
            { prop: "name", label: "姓名",  200 },
            { prop: "address", label: "地址" }
          ]

    3.控制操作列的显示隐藏。操作列,只能写死在el-column里

     showOper:true,

    完整例子:

    <template>
      <div>
        <el-table :data="tableData" style=" 100%" border>
          <el-table-column
            v-for="(item,i) in tableCol"
            :key="i"
            :prop="item.prop"
            :label="item.label"
            :width="item.width"
          ></el-table-column>
           <el-table-column label="操作" v-if="showOper">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
        </el-table>
      </div>
    </template>
    <script>
    export default {
      name: "HelloWorld",
      data() {
        return {
          showOper:true,
          tableData: [
            { date: "2010-1-2", name: "嘻嘻", address: "广州天河东圃" },
            { date: "2010-1-2", name: "嘻嘻", address: "广州天河东圃" },
            { date: "2010-1-2", name: "嘻嘻", address: "广州天河东圃" }
          ],
          tableCol: [
            { prop: "date", label: "日期",  180 },
            { prop: "name", label: "姓名",  200 },
            { prop: "address", label: "地址" }
          ]
        };
      },
      methods: {
          handleEdit(index, row) {
            console.log(index, row);
          },
          handleDelete(index, row) {
            console.log(index, row);
          }
      },
    };
    </script>
    <style lang="css" scoped>
    </style>
  • 相关阅读:
    matlab线性规划
    matlab中fminbnd函数求最小或者组大值
    正方形和球体,利用蒙特卡洛计算pi值
    python 利用cvxopt线性规划
    K-NN(最近邻分类算法 python
    序列匹配,动态规划
    Block中修改局部变量的值为什么必须声明为__block类型
    iOS之初始化对象
    iOS对象模型学习
    C++对象模型学习
  • 原文地址:https://www.cnblogs.com/luguankun/p/11723764.html
Copyright © 2011-2022 走看看