element取表格对应id数据

7 篇文章 0 订阅

第一种写法

<el-button size="mini" type="danger" @click="editor(scope.row)">编辑</el-button>
editor(row) {
				this.dialogTableVisible = true;
				this.id = row.id;								
				var item = this.tableData[this.id - 1];
				this.form.name = item.name;
				this.form.mobi = item.mobi;
				this.form.account = item.account;
				this.form.line = item.line;													
			}

第二种写法

<el-button size="mini" type="danger" @click="editor(scope.row)">编辑</el-button>
editor(row) {
				this.dialogTableVisible = true;
				this.id = row.id;
				this.$axios({
					url: api/index.php/admin/mod/' + this.id,
					method: 'post'
				}).then(res => {
//					console.log(res.data.name);
					var item = res.data;
					this.form.name = item.name;
					this.form.mobi = item.mobi;
					this.form.account = item.account;
					this.form.line = item.line;									
				}).catch(err => {
					console.log(err)
				})
			}
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在使用 element 表格时,可以通过 `span-method` 属性来合并单元格。如果需要使用 `id` 来标识单元格,可以在 `span-method` 方法中进行判断并返回对应的 `rowspan` 和 `colspan` 值。 具体实现步骤如下: 1. 在表格中需要合并的单元格上添加 `id` 属性,例如:`<el-table-column label="姓名" prop="name" :span-method="nameSpanMethod" ><template slot-scope="scope">{{scope.row.name}}</template></el-table-column>`。 2. 在 `methods` 中定义 `nameSpanMethod` 方法,该方法接受两个参数:`{ row, column, rowIndex, columnIndex }`,分别表示当前单元格所在行数据,所在数据,所在行索引和所在索引。该方法需要根据需要合并的单元格的 `id` 进行判断并返回对应的 `rowspan` 和 `colspan` 值。 示例代码如下: ```html <template> <el-table :data="tableData"> <el-table-column label="姓名" prop="name" :span-method="nameSpanMethod"> <template slot-scope="scope">{{scope.row.name}}</template> </el-table-column> <el-table-column label="年龄" prop="age"></el-table-column> <el-table-column label="地址" prop="address"></el-table-column> </el-table> </template> <script> export default { data() { return { tableData: [ { id: 1, name: '张三', age: 18, address: '北京市朝阳区' }, { id: 2, name: '李四', age: 22, address: '上海市浦东新区' }, { id: 3, name: '王五', age: 25, address: '广州市天河区' } ] }; }, methods: { nameSpanMethod({ row, column, rowIndex, columnIndex }) { if (row.id === 1 && columnIndex === 0) { // 合并第一行第一和第二 return { rowspan: 1, colspan: 2 }; } return { rowspan: 1, colspan: 1 }; } } }; </script> ``` 运行以上代码,可以看到第一行第一和第二被合并成了一个单元格,并且在第一中添加了 `id="name"` 属性,用于标识需要合并的单元格。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值