在vue项目中使用vee-validate的正则校验规则,后台返回tailZeroCount,然后动态生成正则表达式,如下:
regexRule() {
let tailZeroCount = this.warePublishData.warePublishVO.tailZeroCount ? this.warePublishData.warePublishVO.tailZeroCount : 3
return /^[0-9]*[0]{`tailZeroCount`}$/
}
<input type="text" v-validate="{
required: true,
regex: regexRule
}"/>
但是打印出来的regexRule还是/^[0-9]*[0]{
tailZeroCount}$/