循环依赖,节点是:yup中的“密码”

问题描述

我收到了上述错误。不知道对象发生了什么。下面是我的对象。

export const loginValidator = yup.object({
  login: yup.string().when('password',{
    is: (v) => v < 9999 && v > 999,then: yup.string().required('Phone No is required').matches(phoneRegExp,'Must be 10 digits'),otherwise: yup.string().email().required('Email is required'),}),password: yup.string().when('login',{
    is: (m) => phoneRegExp.test(m),then: yup
      .string()
      .required('Pin is required')
      .matches(/^[0-9]+$/,'Must be only digits')
      .min(5,'Must be exactly 5 digits')
      .max(5,'Must be exactly 5 digits'),otherwise: yup.string().required('password is required'),});

我遇到的错误

Error: Cyclic dependency,node was:"password"

这是怎么回事 谢谢!!

解决方法

为了避免循环依赖,必须将这些值添加到 yup 中。

[['login','password']]

示例,

export const loginValidator = yup.object().shape(
  {
    login: yup.string().when('password',{
      is: (v) => v < 100000,then: yup.string().required('Phone No is required').matches(phoneRegExp,'Must be 10 digits'),otherwise: yup.string().email().required('Email is required'),}),password: yup.string().when('login',{
      is: (m) => phoneRegExp.test(m),then: yup
        .string()
        .required('Pin is Required')
        .matches(/^[0-9]+$/,'Must be only digits')
        .min(5,'Must be exactly 5 digits')
        .max(5,'Must be exactly 5 digits'),otherwise: yup.string().required('password is required'),},[['login','password']]
);

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...