vue elementui表格点击当前行axios提交当前行的某一列数据

showRow(row,val){
    this.getData2();
},
getData2(){
    let _this = this;
    let data={'changeTime':row.changeTime,'moneySource':row.moneySource};
    
    _this.$axios.post(url,data).then(function (res) {
        console.log(data);
        _this.tableData2 = res.data.list;
        // console.log(res.data.list);
    })
    .catch(function (error) {
        console.log(error);
    });
},

报错row is not defined

阅读 3k
2 个回答

楼上讲得很清楚啦,你的showRow方法套了对另一个方法的调用,单纯看你现在的代码,直接把getData2()的函数体放进去就好了,报undefined因为getData2()中没有row参数

showRow(row,val){
    let _this = this;
    let data={'changeTime':row.changeTime,'moneySource':row.moneySource};
    
    _this.$axios.post(url,data).then(function (res) {
        console.log(data);
        _this.tableData2 = res.data.list;
        // console.log(res.data.list);
    })
    .catch(function (error) {
        console.log(error);
    });
},

或楼上的

showRow(row,val){
    this.getData2(row); //val没用到不传了 还有elment-ui第二个参数是 event      https://element.eleme.cn/2.0/#/zh-CN/component/table
},
getData2(row){
    let _this = this;
    let data={'changeTime':row.changeTime,'moneySource':row.moneySource};
    
    _this.$axios.post(url,data).then(function (res) {
        console.log(data);
        _this.tableData2 = res.data.list;
        // console.log(res.data.list);
    })
    .catch(function (error) {
        console.log(error);
    });
},
showRow(row,val){
    this.getData2(row,val);
},
getData2(row,val){...}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题