Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
717 views
in Technique[技术] by (71.8m points)

element vue 自己写的验证,可以装在一个js里,以后直接rule调用就可以吗

const validateName10 = (rule, value, callback) => {
      var len = 0;
      for (var i = 0; i < value.length; i++) {
        var c = value.charCodeAt(i);
        if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
          len++; //英文字符长度
        } else {
          len += 2; //中文字符长度
        }
      }
      if (len == '') {
        callback(new Error('不能为空'));
      } else if (len > 20) {
        callback(new Error('不能超过10个字'));
      } else {
        // console.log(value.length)
        callback();
      }
    };
 rules: {
        signBtnCopy: [
          [{required: true}, {validator: validateName10, trigger: 'blur' }],
        ],
      },
 <el-form-item label="签到按钮文案:" prop="signBtnCopy">
          <el-input v-model="ruleForm.signBtnCopy" placeholder="请输入"></el-input>
          <span class="hint g-l-complex-i">不超过10字符,英文和数字等于0.5字符</span>
        </el-form-item>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
export const validateName10 = (rule, value, callback) => {

导出后用 import导入就可以直接用了!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...