getBatchList() { this.loading = true; listBatch(this.queryParams).then(response => { this.batchData = response.rows; this.loading = false; }); }, show(id) { this.loading = true; this.open = true this.title = '查看详情' getInformation(id).then(response => { this.form = response.data; const batch = this.batchData.find(item => item.id === this.form.batchId); debugger this.form.batchName = batch ? batch.name : ''; this.loading = false; }); }, 中的this.batchData的值怎么传给show中的this.form
时间: 2024-03-17 19:41:02 浏览: 148
可以在组件中定义一个data属性来存储batchData和form,然后在getBatchList方法中修改batchData的值,然后在show方法中访问batchData的值,找到对应的batch数据,并将其赋值给form中的batchName属性。具体代码如下:
```
data() {
return {
loading: false,
open: false,
title: '',
batchData: [], // 定义batchData
form: { // 定义form
id: '',
name: '',
batchId: '',
batchName: ''
},
queryParams: {
page: 1,
limit: 10
}
}
},
methods: {
getBatchList() {
this.loading = true;
listBatch(this.queryParams).then(response => {
this.batchData = response.rows;
this.loading = false;
});
},
show(id) {
this.loading = true;
this.open = true
this.title = '查看详情'
getInformation(id).then(response => {
this.form = response.data;
const batch = this.batchData.find(item => item.id === this.form.batchId);
this.form.batchName = batch ? batch.name : '';
this.loading = false;
});
},
}
```
在这个例子中,getBatchList方法中修改了batchData的值,然后在show方法中通过this.batchData访问到了batchData的值,并且找到了对应的batch数据,将其赋值给form的batchName属性。注意,在实际开发中,我们需要根据具体的业务需求来定义data属性和方法,这里只是提供一个参考。
阅读全文