vue+element中table踩坑

vue+element中使用table踩坑

1.开发环境 vue.js
2.电脑系统 windows 10 专业版
3.在开发的过程当中,咱们常常会使用 vue+element进行开发,使用这样的效果! image.png
4.总体思路:vue

使用 vue + element 进行开发,使用 element 中的 table ### 树形数据与懒加载

5.在项目中,咱们常常会点击的时候向后台传一些值,通常都是 id 的比较多,那么在点击的时候怎么获取到 对应的 id 呢?
方法以下:windows

//在vue模板中添加以下代码:浏览器

<el-table-column
          fixed="right"
          label="操做"
          width="140">
          <template slot-scope="scope">
            <el-button
              @click.native.prevent="handleAdd(scope.$index,tableData)"
              type="text"
              size="small">
              新增
            </el-button>
            <el-button
              @click="xiugai(scope.row)"
              type="text"
              size="small">
              修改
            </el-button>
            <el-button
              @click.native.prevent="deleteRow(scope.$index,tableData)"
              type="text"
              size="small">
              移除
            </el-button>
            <!-- 修改 按钮-->
          </template>
        </el-table-column>

6.在methods 中添加以下代码:this

//点击修改
      xiugai(  rows){
        var _this=this;
        console.log(rows)
        console.log("我是修改------------------------");
        // console.log(rows[index]);
        // _this.bianhao=rows[index].code;
        // _this.mingcheng=rows[index].name;
        // // _this.handleAdd();
        // _this.handleEdit();

        console.log("我是对应的id");
        console.log(rows[index].id);
        _this.chenxgid=rows[index].id;
        var dd={
          id:rows[index].id
        }

        chenxiugai(dd).then(res=>{
          console.log("传完id以后,后台返回对应的数据");
          console.log(res);
          if (res.id!=""){
            //若是 id不为空,表示有数据,
            _this.handleEdit();
          //  把后台的数据渲染到表单上面
            _this.hqxg=res.data;
            _this.bianhao=_this.hqxg.code;
            _this.mingcheng=_this.hqxg.name;

          }
        })
      },

7.在浏览器的控制台中,你就会看到对应的输出结果。是否是很简单,是否是很棒!让咱们一块儿努力走向巅峰!在这个领域不要认输,不要低头,不要放弃!
//本期的教程到了这里就结束啦,但愿对你有所帮助!让咱们一块儿加油!spa

相关文章
相关标签/搜索