Home > Web Front-end > JS Tutorial > body text

VUE and Element UI make in-line editing of tables

php中世界最好的语言
Release: 2018-03-12 11:27:06
Original
8815 people have browsed it

This time I will bring you VUE and Element UI to make in-line editing of tables. What are the precautions for making in-line editing of tables with VUE and Element UI? The following is a practical case, let's take a look.

VUE and Element UI make in-line editing of tables

demo

The principle is to control the bound input control and display value through Css, and hide or display the control under the selected row style

<!DOCTYPE html><html><head>
    <meta charset="UTF-8">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-default/index.css">
    <style>
        * {    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
}    </style></head><body>
    <div id="app">
        <el-table :data="tableData" class="tb-edit" style="width: 100%" highlight-current-row @row-click="handleCurrentChange">
            <el-table-column label="日期" width="180">
                <template scope="scope">
                    <el-input size="small" v-model="scope.row.date" placeholder="请输入内容" @change="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="请输入内容" @change="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="请输入内容" @change="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></body><script src="https://unpkg.com/vue/dist/vue.js"></script><script src="https://unpkg.com/element-ui/lib/index.js"></script><script>
    var app = new Vue({        el: &#39;#app&#39;,        data: {            tableData: [{                date: &#39;2016-05-02&#39;,                name: &#39;王小虎&#39;,                address: &#39;上海市普陀区金沙江路 1518 弄&#39;
            }, {                date: &#39;2016-05-04&#39;,                name: &#39;王小虎&#39;,                address: &#39;上海市普陀区金沙江路 1517 弄&#39;
            }, {                date: &#39;2016-05-01&#39;,                name: &#39;王小虎&#39;,                address: &#39;上海市普陀区金沙江路 1519 弄&#39;
            }, {                date: &#39;2016-05-03&#39;,                name: &#39;王小虎&#39;,                address: &#39;上海市普陀区金沙江路 1516 弄&#39;
            }]
        },        methods: {
            handleCurrentChange(row, event, column) {                console.log(row, event, column, event.currentTarget)
            },
            handleEdit(index, row) {                console.log(index, row);
            },
            handleDelete(index, row) {                console.log(index, row);
            }
        }
    })</script> </html>
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:

How to send emails through qq mailbox in python3

##Detailed explanation of the separation of front-end and back-end development of Golang+Nodejs

The above is the detailed content of VUE and Element UI make in-line editing of tables. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!