问题:我们想要在一个表单里面。有多个按钮,但是点击到只剩下一个按钮之后那个按钮不可点击。


原先:

< template scope= "scope" >
< el-switch v-model=" scope. row. state"
        :on-value=1
        :off-value=0 on-text= "否" off-text= "是"
v-if=" scope. row. assign== 1"
        @change=" setChange( scope. $index, scope. row)" >
</ el-switch >
</ template >

解决方法:我们在可以每一个switch里面添加一个属性,之后在属性里面做判断

< template scope= "scope" >
< el-switch v-model=" scope. row. state"
        :on-value=1
        :off-value=0 on-text= "否" off-text= "是"
v-if=" scope. row. assign== 1"
        @change=" setChange( scope. $index, scope. row)"
        :disabled="scope.row.state==1&&isDisabled">
</ el-switch >
</ template >


之后在script中添加如下方法,判断每次点击的时候。剩下的switch的状态。在做判断

setChange( index, row) {
let arr = [];
// 改变后的值
if( row. state== 1){
row. state= 0;
} else{
row. state= 1;
}
this. list1. forEach( element => {
if( element. assign== 1&& element. state== 1){
arr. push( 1);
}
});
// console.log(arr.length);
//判断最后一个开关是否禁用
if( arr. length<= 1){
this. isDisabled= true;
} else{
this. isDisabled= false;
}





Logo

前往低代码交流专区

更多推荐