使用计算属性实现
<div v-for="(item, index) in csObj" :key="index">
<el-input-number
v-model="item.selectNum"
:min="0"
:max="maxQuantit?cs1(index):Infinity"
>
</el-input-number>
</div>
data() {
return {
maxQuantit: 5,
csObj: [
{
selectNum: 0
},
{
selectNum: 0
},
{
selectNum: 0
},
{
selectNum: 0
}
],
}
}
computed: {
cs1() {
return (data) => {
let allSelect = 0
let maxQuantit = this.maxQuantit
this.csObj.forEach((item, index) => {
if (index !== data) {
allSelect += item.selectNum
}
})
return maxQuantit-allSelect
}
}
}