使用vue.js+Element UI 实现报个增删改查

这边使用VUE是直接引用VUE.JS 没有使用脚手架搭建

其中index.css index.js是element ui中可以到这边去下载

https://unpkg.com/element-ui@2.4.8/

vue.js是VUE官网里面想下载的地址如下

https://cdn.jsdelivr.net/npm/vue/dist/vue.js

HTML代码

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <!-- import CSS -->
    <link rel="stylesheet" href="../css/index.css">
    <link rel="stylesheet" href="../css/table.css">
</head>
<body>
<div id="app" style="width: 800px">
    <template>
        <el-button size="small" type="primary" @click="addRow">新增</el-button>
        <el-button size="small" type="warning" @click="cancelHighlight">保存</el-button>
    </template>
    <el-table :data="tableData" class="tb-edit" style="width: 100%" highlight-current-row
              @row-click="handleCurrentChange" ref="mytable">
        <el-table-column label="日期" width="180">
            <template scope="scope">
                <el-input size="small" v-model="scope.row.date" placeholder="请输入内容" @row-click="handleEdit(scope.$index, scope.row)"></el-input> <span>{{scope.row.date}}</span>
            </template>
        </el-table-column>
        <el-table-column label="姓名" width="180">
            <template scope="scope">
                <el-input size="small" v-model="scope.row.name" placeholder="请输入内容" @row-click="handleEdit(scope.$index, scope.row)"></el-input> <span>{{scope.row.name}}</span>
            </template>
        </el-table-column>
        <el-table-column prop="address" label="地址">
            <template scope="scope">
                <el-input size="small" v-model="scope.row.address" placeholder="请输入内容" @row-click="handleEdit(scope.$index, scope.row)"></el-input> <span>{{scope.row.address}}</span>
            </template>
        </el-table-column>
        <el-table-column label="操作">
            <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>
    <br>数据:{{tableData}}</div>
</div>
</body>
<!-- import Vue before Element -->
<script src="../js/vue.js"></script>
<script src="../js/index.js"></script>
<script src="../js/table.js"></script>
</html>

css 代码:

* {
    margin: 0;
    padding: 0
}
body {
    font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, SimSun, sans-serif;
    overflow: auto;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
}
.tb-edit .el-input {
    display: none
}
.tb-edit .current-row .el-input {
    display: block
}
.tb-edit .current-row .el-input+span {
    display: none
}

js 代码

var app = new Vue({
    el: '#app',
    data: {
        tableData: [{
            date: '2016-05-02',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1518 弄'
        }, {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1517 弄'
        }, {
            date: '2016-05-01',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1519 弄'
        }, {
            date: '2016-05-03',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1516 弄'
        }]
    },

    methods:{
        /*选中行*/
        handleCurrentChange:function(row, event, column){
        },
        /*点击编辑*/
        handleEdit:function(index, row) {

        },
        /*点击删除*/
        handleDelete:function(index, row) {
            this.tableData.splice(this.tableData.indexOf(row),1);
        },
        /*点击新增*/
        addRow:function(){
            this.tableData.push({date:'',name:'',address:''});
            this.$refs.mytable.setCurrentRow(this.tableData[this.tableData.length-1])
        },
        cancelHighlight:function (index,row) {
            console.log(index)
            this.$refs.mytable.setCurrentRow()
        }
    }
})
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值