element 使用 dialog 可以通过点击事件 把 tables的 scope.row 传过去吗
时间: 2024-04-29 12:24:06 浏览: 11
可以。可以使用 $emit 或者 $parent.$emit 在点击事件中将 tables 的 scope.row 传递给 dialog 组件。在 dialog 组件中,可以监听该事件并接收传递过来的数据。具体实现可以参考以下代码:
在 tables 组件中:
```
<el-table-column label="操作">
<template slot-scope="scope">
<el-button @click="handleClick(scope.row)">编辑</el-button>
</template>
</el-table-column>
methods: {
handleClick(row) {
this.$emit('edit', row);
}
}
```
在 dialog 组件中:
```
<template>
<el-dialog :visible.sync="dialogVisible">
<el-form>
<el-form-item label="姓名">
<el-input v-model="currentRow.name"></el-input>
</el-form-item>
<el-form-item label="年龄">
<el-input v-model="currentRow.age"></el-input>
</el-form-item>
</el-form>
</el-dialog>
</template>
<script>
export default {
data() {
return {
dialogVisible: false,
currentRow: {}
}
},
mounted() {
this.$parent.$on('edit', row => {
this.dialogVisible = true;
this.currentRow = row;
});
}
}
</script>
```