通过复选框是否选中的状态将字符串中的0转变成1。
<el-table ref="itemref" :data="itemList" border highlight-current-row stripe @selection-change="handleSelectionChange"> <el-table-column type="selection" width="55" /> <el-table-column type="index" label="序号" min-width="70"> <template slot-scope="scope"> {{ scope.$index + (formData.pageInfo.pageNumber - 1) * formData.pageInfo.pageSize + 1 }} </template> </el-table-column> <el-table-column prop="name" label="姓名" show-overflow-tooltip> </el-table-column></el-table>
itemList : [] //将选中的选项暂存在该数组中itemNum: ['0', '0', '0', '0', '0', '0'],items: '', //最终失去的字符串,传递给后端itemList: [ { itemIndex: 0, name: "第一项" }, { itemIndex: 1, name: "第二项" }, { itemIndex: 2, name: "第三项" }, { itemIndex: 3, name: "第四项" }, { itemIndex: 4, name: "第五项" }, { itemIndex: 5, name: "第六项" }, ],handleSelectionChange(val) { this.itemList = val; //将选中的项放入到数组中 this.itemList.forEach(item => { this.itemNum[item.itemIndex] = 1 //定位将0赋值为1 this.items = this.itemNum.join('').toString() //将数组转换成字符串 });},// this.$refs.itemref.clearSelection(); //清空十四项多选状态 多用于弹窗敞开时