# 系统规则校验配置
* * * * *
* **引用业务级规则**:src/pages/…/业务模块.vue
* 参考文件:src/pages/sys/userAdd.vue
* 参考代码:
~~~
import rules from './userAdd.rule'
data(){
return {
rules: rules,
}
}
~~~
* **业务级规则配置**:src/pages/…/业务模块.rule.js
* 参考文件:src/pages/sys/userAdd.rule.js
* 参考代码:
~~~
import {checkPhone,checkTel} from '../../services/base.rules'
export default {
telephone: [
{required: true, message: '请输入手机号码', trigger: 'blur'},
{validator: checkPhone, message: '请输入正确的手机号码',trigger: 'change'}
],
}
~~~
* **系统级规则配置**:base.rules.js
* 参考文件:src/services/base.rules.js
* 参考代码:
~~~
export function checkPhone(rule, value, callback) {
if (!(/^1[34578]\d{9}$/.test(value))) {
callback(new Error(rule.message==undefined?'请输入正确的手机号码!':rule.message));
return;
}
}
~~~