this is my sample code and i need to pass the data inside the axios.get.
我需要从console.log(this.var1)的位置获取this.var1的值
newModalMultiple(){
this.var1=0;
for( i = 0; i < this.checkedNames.length; i++)
{
axios.get('/api/getjvlfilter', {params: {JVLHDRID: this.checkedNames[i]}})
.then(response => {
this.jvlfilter = response.data;
this.var1=this.jvlfilter[0].BillAmount;
})
}
console.log(this.var1);
}
使用另一个变量var vm = this;
,并在get函数中将this
替换为vm
newModalMultiple(){
var vm = this;
vm.var1=0;
for( i = 0; i < this.checkedNames.length; i++)
{
axios.get('/api/getjvlfilter', {params: {JVLHDRID: vm.checkedNames[i]}})
.then(response => {
vm.jvlfilter = response.data;
vm.var1= vm.jvlfilter[0].BillAmount;
})
}
console.log(vm.var1);
}