相信很多使用iview的朋友,在用到table,都會遇到需要使用selection的場景,但是總會有那么一個產品汪,覺得iview的單選效果不好,非要用selection的來做單選,那么下面這個方法就能解決這個問題:
{
title: '選中',
align:'center',
key: 'checkBox',
render:(h,params)=>{
return h('div',[
h('Checkbox',{
props:{
value:params.row.checkBox
},
on:{
'on-change':(e)=>{
console.log(e)
this.tableData.forEach((items)=>{ //先取消所有對象的勾選,checkBox設置為false
this.$set(items,'checkBox',false)
});
this.tableData[params.index].checkBox = e; //再將勾選的對象的checkBox設置為true
}
}
})
])
}
},