BaseTable.vue 2.6 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
            </el-table-column>
            <el-table-column prop="address" label="地址" :formatter="formatter">
            </el-table-column>
L
lin-xin 已提交
17
            <el-table-column label="操作" width="180">
L
lin-xin 已提交
18 19 20 21 22 23 24 25 26
                <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 已提交
27
            <el-pagination
L
lin-xin 已提交
28
                    @current-change ="handleCurrentChange"
L
lin-xin 已提交
29 30
                    layout="prev, pager, next"
                    :total="1000">
L
lin-xin 已提交
31 32 33 34 35 36 37 38 39
            </el-pagination>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
L
lin-xin 已提交
40
                url: '../../../static/vuetable.json',
L
lin-xin 已提交
41 42
                tableData: [],
                cur_page: 1
L
lin-xin 已提交
43 44
            }
        },
L
lin-xin 已提交
45 46 47
        created(){
            this.getData();
        },
L
lin-xin 已提交
48
        methods: {
L
lin-xin 已提交
49 50 51 52 53 54
            handleCurrentChange(val){
                this.cur_page = val;
                this.getData();
            },
            getData(){
                let self = this;
L
lin-xin 已提交
55 56 57 58 59
                if(process.env.NODE_ENV === 'development'){
                    self.url = '/ms/table/list';
                };
                self.$axios.post(self.url, {page:self.cur_page}).then((res) => {
                    self.tableData = res.data.list;
L
lin-xin 已提交
60 61
                })
            },
L
lin-xin 已提交
62 63 64 65 66 67 68
            formatter(row, column) {
                return row.address;
            },
            filterTag(value, row) {
                return row.tag === value;
            },
            handleEdit(index, row) {
L
lin-xin 已提交
69
                this.$message('编辑第'+(index+1)+'');
L
lin-xin 已提交
70 71
            },
            handleDelete(index, row) {
L
lin-xin 已提交
72
                this.$message.error('删除第'+(index+1)+'');
L
lin-xin 已提交
73 74 75 76
            }
        }
    }
</script>