element-ui自定义表单校验:
表单校验--根据当前部门id,找到所有子部门相关的数据,判断是否重复
const checkNameRepeat = async (rule, value, callback) => {
// 先要获取最新的组织架构数据
const { depts } = await getDepartments();
// depts是所有的部门数据
// 如何去找技术部所有的子节点
const isRepeat = depts.filter((item) => item.pid === this.treeNode.id).some((item) => item.name === value);
isRepeat ? callback(new Error(`同级部门下已经有${value}的部门了`)) : callback();
};
.native修饰符:会将原生事件绑定到组件
<base-input @focus.native="onFocus"></base-input>
.sync修饰符:子父通信的语法糖
用法:
//父组件
<AddDept @addDepts='getDepartments'
:show-dialog.sync="showDialog"
:treeNode='node'/>
----------------------------------------
//子组件
this.$emit("update:showDialog",false);