这个讲的是无论emelent表格是选中还是未选中都不可勾选,下面有完整代码示例
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <!-- 引入样式 --> <link href="https://cdn.bootcdn.net/ajax/libs/element-ui/2.14.1/theme-chalk/index.css" rel="stylesheet"> <!-- 引入组件库 --> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/element-ui/2.14.1/index.js"></script> </head> <body> <div id="app"> <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange"> <el-table-column type="selection" :selectable="checkSelectable" width="55"> </el-table-column> <el-table-column label="日期" width="120"> <template slot-scope="scope">{{ scope.row.date }}</template> </el-table-column> <el-table-column prop="name" label="姓名" width="120"> </el-table-column> <el-table-column prop="address" label="地址" show-overflow-tooltip> </el-table-column> </el-table> </div> <script type="text/javascript"> var app = new Vue({ el: '#app', data: { tableData: [{ date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄', zhuangtai:'2' }, { date: '2016-05-02', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄', zhuangtai:'1' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄', zhuangtai:'2' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄', zhuangtai:'2' }, { date: '2016-05-08', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄', zhuangtai:'1' }, { date: '2016-05-06', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄', zhuangtai:'1' }, { date: '2016-05-07', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄', zhuangtai:'2' }], multipleSelection: [] }, mounted() { // 根据zhuangtai判断默认选中 for(let i=0;i<this.tableData.length;i++){ if(this.tableData[i].zhuangtai=='2'){ this.$refs.multipleTable.toggleRowSelection(this.tableData[i]); } } }, methods: { // 根据zhuangtai判断禁止选择 checkSelectable(row){ return row.zhuangtai !== '2' }, // 获取选中的数据 handleSelectionChange(val) { console.log('下面打印的是选中的数据') console.log(val) this.multipleSelection = val; }, } }) </script> </body> </html>
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!