handleChange(row,index) { this.warehouselist=[] this.$axios.get(GetQueryParams(this.$GoUrl + '/api/go/store/getStoreByCompany',{ companyID:row.company_id })).then(resp => { if (resp.code == 2000) { this.warehouselist=resp.data console.log(resp.data) } }).catch(err => { console.log(err) })修改当前行数据
时间: 2024-02-10 10:10:39 浏览: 26
根据您提供的代码来看,handleChange函数似乎只是请求了公司ID对应的仓库列表,没有修改当前行数据的操作。如果您想要修改当前行数据,您需要在函数中找到对应的数据对象,然后修改它的属性值。例如,如果您的表格数据是存储在this.tableData中的数组,那么您可以这样操作:
```
handleChange(row, index) {
// 找到对应的数据对象
const dataObj = this.tableData[index];
// 修改数据对象的属性值
dataObj.company_id = row.company_id;
// 发送请求获取仓库列表
this.$axios.get(GetQueryParams(this.$GoUrl + '/api/go/store/getStoreByCompany',{
companyID: row.company_id
})).then(resp => {
if (resp.code == 2000) {
// 修改数据对象的其他属性值
dataObj.warehouse_list = resp.data;
console.log(resp.data);
}
}).catch(err => {
console.log(err);
});
}
```
注意,这里只是一个示例代码,具体的操作需要根据您的实际需求进行修改。
相关问题
handleChange(row,index) { this.warehouselist=[] this.$axios.get(GetQueryParams(this.$GoUrl + '/api/go/store/getStoreByCompany',{ companyID:row.company_id })).then(resp => { if (resp.code == 2000) { row[index].warehouselist=resp.data console.log(resp.data) } }).catch(err => { console.log(err) }) },
根据您提供的代码来看,修改当前行数据的代码还是有问题的。row是一个对象,而不是数组,因此不能使用row[index]的方式来访问数据属性。如果您想要修改当前行数据的warehouselist属性值,您可以直接使用row.warehouselist的方式来修改,例如:
```
handleChange(row, index) {
this.$axios.get(GetQueryParams(this.$GoUrl + '/api/go/store/getStoreByCompany', {
companyID: row.company_id
})).then(resp => {
if (resp.code == 2000) {
// 直接修改当前行数据的warehouselist属性值
row.warehouselist = resp.data;
console.log(resp.data);
}
}).catch(err => {
console.log(err);
});
}
```
另外,您在函数中也没有对this.warehouselist进行任何操作,因此这个变量似乎并没有用处。如果您想要存储所有的仓库列表,您可以在组件的data中定义一个变量来存储,例如:
```
data() {
return {
warehouselist: []
};
},
methods: {
handleChange(row, index) {
this.$axios.get(GetQueryParams(this.$GoUrl + '/api/go/store/getStoreByCompany', {
companyID: row.company_id
})).then(resp => {
if (resp.code == 2000) {
// 存储所有的仓库列表
this.warehouselist = resp.data;
// 修改当前行数据的warehouselist属性值
row.warehouselist = resp.data;
console.log(resp.data);
}
}).catch(err => {
console.log(err);
});
}
}
```
this.$axios.get和 this.axios.get的区别
this.$axios.get 是在Vue实例的上下文中使用axios实例的方式,可以直接在Vue组件的methods中使用,例如:
```
export default {
methods: {
async fetchData() {
const response = await this.$axios.get('/api/data');
console.log(response.data);
}
}
}
```
this.axios.get 则需要先导入axios库,然后再使用,例如:
```
import axios from 'axios';
export default {
methods: {
async fetchData() {
const response = await axios.get('/api/data');
console.log(response.data);
}
}
}
```
总结来说,this.$axios.get 是使用Vue插件的方式来使用axios,而 this.axios.get 则需要手动导入axios库。