:name="'actualWgh' + index" :data-vv-as="$t('message.weight')">
<span v-show="errors.has('actualWgh' + index, 'newsletter' + index)" class="help-block">{{ errors.first('actualWgh' + index, 'newsletter' + index) }}</span>
</div>
<div class="form-group">
<label>过磅单</label>
<input type="text" class="form-control" v-model.trim="p1.weightNo">
</div>
</div>
<div class="col-xs-12 text-right" style="border-top: 1px solid #eee;padding: 10px 15px;">
<button class="btn btn-warning" @click="doSave(p1, index)">保存</button>
</div>
</div>
</div>
*
carList: [{}, {}]
* data-vv-scope: [type='string'] 属性的值的类型是 string,表示定义了一个区域,在校验的时候,通过属性值 让validator 可以找到当前应该校验的区域。此时通过 验证器提供的方法validate(scopeName)就可以校验当前区域了。
doSave (obj, i) {
var _self = this
var validateScope = 'newsletter' + i
this.$validator.validate(validateScope + '.*').then((result) => {
if (result) {
// 提交数据
_self.doSaveAfterCheck()
}
})
}/*
errors.has(field, scope) 返回一个true / false
errors.has('actualWgh' + index, 'newsletter' + index)}" 表示验证区域是 data-vv-scope = 'newsletter' + index 验证的字段是属性 name ='actualWgh' + index
first(field,scope) 返回与特定字段关联或由选择器指定的第一条错误消息,前提是作用域将查找该范围内的消息,
*/
<div class="form-group" :class="{'has-error': errors.has('actualWgh' + index, 'newsletter' + index)}">
<label>总重(kg) <i class="errMsg">*</i></label>
<input type="text" class="form-control" v-model.trim="p1.actualWgh" :data-vv-scope="'newsletter' + index"
v-validate="{required: true, decimal:2, min_value: 0, max_value: p1.planWgh}"
:name="'actualWgh' + index" :data-vv-as="$t('message.weight')">
<span v-show="errors.has('actualWgh' + index, 'newsletter' + index)" class="help-block">{{ errors.first('actualWgh' + index, 'newsletter' + index) }}</span>
</div>
场景2 : 页面有多个校验。当保存的时候,需要全部校验。这个场景官方提供2种方法.
this.$validator.validate().then((result) => {
if (result) {
// 提交数据。
// result是一个boolean值。true 表示没有触发错误规则,false 表示页面有非法值,触发错误
_self.doSaveAfterCheck()










