Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何设置动态输入的最大值?_Javascript_Vue.js_Vee Validate - Fatal编程技术网

Javascript 如何设置动态输入的最大值?

Javascript 如何设置动态输入的最大值?,javascript,vue.js,vee-validate,Javascript,Vue.js,Vee Validate,我有带有动态输入的vue表单。 第一。用户以表格形式登记股份总额 第二。他通过添加所需的动态投入,开始向股东部分发行该总额 他提交了表格。 我的任务是避免过度争论 我不知道如何避免向股东发行的股份超过其登记总数/ Ex: totalSharesAmount = 100 shareholder[0] - shares_amount = 50 shareholder[1] - shares_amount = 20 //70 total shareholder[2] - shares_amount

我有带有动态输入的vue表单。

第一。用户以表格形式登记股份总额
第二。他通过添加所需的动态投入,开始向股东部分发行该总额
他提交了表格。
我的任务是避免过度争论

我不知道如何避免向股东发行的股份超过其登记总数/

Ex:
totalSharesAmount = 100
shareholder[0] - shares_amount = 50 
shareholder[1] - shares_amount = 20 //70 total
shareholder[2] - shares_amount = 30 //100 total. can't be more than 100
我的数据:

data() {
return {
    totatSharesAmount: 100
    shareholders: [{share_amount: '', share_price: ''}]
    }
}
我的验证方法(计算)和这里我需要帮助:

sharesToFounders() {
    return {
      required: true,
      max_value: this.totalSharesAmount - this.shareholder['shares_amount'] //need help here
   }
}

您需要一个计算机来跟踪剩余的点。当还有点时,需要一个函数将元素添加到数组中。你需要连接一个函数来调用这个函数。下面的代码片段就是这样做的

newvue({
el:“#应用程序”,
数据(){
返回{
总分:100分,
发现点:[]
};
},
方法:{
addPoint(){
这个是.foundersPoints.push({
点数金额:空,
价格点:空
});
}
},
观察:{
其余要点:{
处理程序(v){
if(v>0&&this.pointValues.every((v)=>v>0)){
this.addPoint();
}
如果(v.o.points_amount>0);
}
},
立即:对
}
},
计算:{
pointValues(){
返回此.foundersPoints.map((o)=>o.points\u金额);
},
剩余积分(){
const used=this.pointValues.reduce((a,b)=>a+b,0);
返回此值。totalPoints-已使用;
}
}
});
:无效{
边框:纯红2px;
}

剩余股份:{{remainingPoints}}

解决方法之一:跟踪当前总数,在输入时,使用验证器方法允许用户更改或阻止更改

标记:

<div id="app">
  <div class="row"><span>Total:</span><input type="number" v-model="totalPoints"></div>
  <div v-for="(item, index) in foundersPoints" class="row">
    <input type="number" v-on:input="updateValue(index)" v-model="foundersPoints[index].points_amount"><span v-if="foundersPoints[index].alert" class="alert">{{foundersPoints[index].alert}} <button v-on:click="dismissAlert(index)">OK</button></span>
  </div>
</div>
用于跟踪以下各项的当前总计(计算属性):

computed: {
  tempSum() {
    const pointsAmounts = this.foundersPoints.map(item => Number(item.points_amount));
    return pointsAmounts.reduce((acc, t) => acc + Number(t), 0);
  }
},
在这把小提琴中看到它的动作:


这不适用于用户减少允许的总分的情况。(用户将总数设为60,然后将三个点的值分别设为20。如果用户将总数设为40,那么加起来等于60的输入会发生什么情况?

您可能应该更详细地描述您正在寻找的行为。你是说你想让新的输入显示出来,直到用户通过填写来使用所有的点吗?@RoyJ好的,我在我的帖子中做了一些更改,希望能更好地描述这个案例哦,这看起来像我要找的!我现在要试试。谢谢
computed: {
  tempSum() {
    const pointsAmounts = this.foundersPoints.map(item => Number(item.points_amount));
    return pointsAmounts.reduce((acc, t) => acc + Number(t), 0);
  }
},