BaseTable.vue 3.2 KB
Newer Older
L
lin-xin 已提交
1 2 3 4
<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
L
lin-xin 已提交
5
                <el-breadcrumb-item><i class="el-icon-menu"></i> 表格</el-breadcrumb-item>
L
lin-xin 已提交
6 7 8 9 10
                <el-breadcrumb-item>基础表格</el-breadcrumb-item>
            </el-breadcrumb>
        </div>

        <el-table :data="tableData" border style="width: 100%">
L
lin-xin 已提交
11
            <el-table-column prop="date" label="日期" sortable width="150">
L
lin-xin 已提交
12
            </el-table-column>
L
lin-xin 已提交
13
            <el-table-column prop="name" label="姓名" width="120">
L
lin-xin 已提交
14 15 16 17 18 19 20 21 22 23 24
            </el-table-column>
            <el-table-column prop="address" label="地址" :formatter="formatter">
            </el-table-column>
            <el-table-column prop="tag" label="标签" width="120"
                    :filters="[{ text: '家', value: '家' }, { text: '公司', value: '公司' }]"
                    :filter-method="filterTag">
                <template scope="scope">
                    <el-tag :type="scope.row.tag === '家' ? 'primary' : 'success'" close-transition>{{scope.row.tag}}
                    </el-tag>
                </template>
            </el-table-column>
L
lin-xin 已提交
25
            <el-table-column label="操作" width="180">
L
lin-xin 已提交
26 27 28 29 30 31 32 33 34
                <template scope="scope">
                    <el-button size="small"
                            @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                    <el-button size="small" type="danger"
                            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="pagination">
L
lin-xin 已提交
35 36 37
            <el-pagination
                    layout="prev, pager, next"
                    :total="1000">
L
lin-xin 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
            </el-pagination>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                tableData: [{
                    date: '2017-02-02',
                    name: '小天才',
                    address: '东莞市长安镇步步高大道18号',
                    tag: ''
                }, {
                    date: '2017-02-04',
                    name: '小天才',
                    address: '东莞市长安镇步步高大道17号',
                    tag: '公司'
                }, {
                    date: '2017-02-01',
                    name: '小天才',
                    address: '东莞市长安镇步步高大道19号',
                    tag: ''
                }, {
                    date: '2017-02-03',
                    name: '小天才',
                    address: '东莞市长安镇步步高大道16号',
                    tag: '公司'
                }]
            }
        },
        methods: {
            formatter(row, column) {
                return row.address;
            },
            filterTag(value, row) {
                return row.tag === value;
            },
            handleEdit(index, row) {
L
lin-xin 已提交
78
                this.$message('编辑第'+(index+1)+'');
L
lin-xin 已提交
79 80
            },
            handleDelete(index, row) {
L
lin-xin 已提交
81
                this.$message.error('删除第'+(index+1)+'');
L
lin-xin 已提交
82 83 84 85
            }
        }
    }
</script>