element.ui增删改

一级目录

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>同学录</title>
    <!-- <link rel="stylesheet" href="./style/index.css"> -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <style>
        #app {
            width: 1024px;
            margin: 0 auto;
        }
        
        .add-btn {
            margin-top: 20px;
            width: 100%;
        }
        
        .body {
            margin-top: 20px;
        }
    </style>
</head>

<body>
    <div id="app">
        <h1>同学录</h1>
        <div class="head">
            <el-row :gutter="20">
                <el-col :span="6">
                    <el-input v-model="userInfo.name" placeholder="请输入姓名"></el-input>
                </el-col>
                <el-col :span="6">
                    <el-input v-model="userInfo.sex" placeholder="请输入性别"></el-input>
                </el-col>
                <el-col :span="6">
                    <el-input v-model="userInfo.del" placeholder="请输入电话号码"></el-input>
                </el-col>
                <el-col :span="6">
                    <el-date-picker v-model="userInfo.day" type="date" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" placeholder="选择日期">
                    </el-date-picker>
                </el-col>
            </el-row>
            <el-button type="primary" class="add-btn" @click="addUser">添加</el-button>
        </div>
        <div class="body">
            <template>
        <el-table
          :data="tableData"
          stripe
          style="width: 100%">
          <el-table-column
            prop="date"
            label="序号"
            width="180">
            <template slot-scope="scope">
              {{scope.$index + 1}}
            </template>
            </el-table-column>
            <el-table-column prop="name" label="姓名" width="180">
            </el-table-column>
            <el-table-column prop="sex" label="性别">
            </el-table-column>
            <el-table-column prop="del" label="电话号码">
            </el-table-column>
            <el-table-column prop="day" label="生日">
            </el-table-column>
            <el-table-column prop="caozuo" label="操作">
                <template slot-scope="scope">
                <el-button type="primary" icon="el-icon-edit" @click="editUser(scope.row,scope.$index)" circle></el-button>
                <el-button type="danger" icon="el-icon-delete" @click="delUser(scope.$index)" circle></el-button>
              </template>
            </el-table-column>
            </el-table>
            </template>
        </div>
        <el-dialog title="编辑用户信息" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
            <div>
                <el-form ref="form" :model="obj" label-width="80px">
                    <el-form-item label="姓名">
                        <el-input v-model="obj.name"></el-input>
                    </el-form-item>
                    <el-form-item label="性别">
                        <el-input v-model="obj.sex"></el-input>
                    </el-form-item>
                    <el-form-item label="电话号码">
                        <el-input v-model="obj.del"></el-input>
                    </el-form-item>
                    <el-form-item label="生日">
                        <el-date-picker v-model="obj.day" type="date" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" placeholder="选择日期">
                        </el-date-picker>
                    </el-form-item>
                </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="confirm">确 定</el-button>
        </span>
        </el-dialog>


    </div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="./javascript/index.js">
</script>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
使用Vue和Element UI可以非常方便地实现表格的增删功能。 首先,我们需要在Vue中引入Element UI的Table组件,用于显示表格数据。可以通过在Vue组件中引入以下代码来实现: ```javascript <template> <el-table :data="tableData"> <!-- 表格列的定义 --> </el-table> </template> <script> import { Table } from 'element-ui'; export default { components: { 'el-table': Table }, data() { return { tableData: [] // 表格数据 }; } } </script> ``` 接下来,我们需要在data函数中定义tableData,用于存储表格的数据。可以通过向tableData数组中添加对象的方式来定义表格的行数据。例如: ```javascript data() { return { tableData: [ { name: 'Alice', age: 20 }, { name: 'Bob', age: 25 }, { name: 'Charlie', age: 30 } ] }; } ``` 然后,我们可以使用Element UI提供的Button组件来实现新增、删除和编辑操作。例如: ```javascript <el-button @click="addRow">新增</el-button> <el-button @click="deleteRow">删除</el-button> <el-button @click="editRow">编辑</el-button> ``` 在Vue组件的methods中定义对应的方法来实现表格的增删功能。例如: ```javascript methods: { // 新增一行数据 addRow() { this.tableData.push({ name: '', age: '' }); }, // 删除选中的行数据 deleteRow() { const selectedRows = this.$refs.table.selection; selectedRows.forEach(row => { const index = this.tableData.indexOf(row); this.tableData.splice(index, 1); }); }, // 编辑选中的行数据 editRow() { // 编辑操作 } } ``` 通过以上步骤,即可使用Vue和Element UI实现表格的增删功能。根据具体需求,可以进一步自定义表格列的定义、编辑操作等功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Vue1024

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值