TypeError:无法读取未定义的属性“ setDate”

时间:2018-12-24 08:25:44

标签: node.js mongodb express mean-stack

尝试从date.now开始增加到期日期时出现此错误

function reducer(state, action) {
  if(action.type === 'timeOut'){
    this.setState({ 
      loggedIn : false,
      logoutMessage : 'Your session has timed out',
      errorOpen : true, 
    });
  }else if(action.type === 'error'){
    this.setState({ 
      loggedIn : false,
      logoutMessage : 'An error has occured',
      errorOpen : true,
    });
  }else if(action.type === 'logout'){
    this.setState({ loggedIn : false });
  }
}

const store = createStore(reducer);

export default class LoginRegister extends Component {
  constructor(props){
    super(props);
    this.state = {
      onLoginPage: true,
      loggedIn: false,
      loginError: false,
      logoutMessage: '',
      errorOpen: false,
    }
  }

这里的折扣是架构,有效期限是字段。

预先感谢

2 个答案:

答案 0 :(得分:0)

您的Discount.expiry没有setDate方法,如果:

,它将运行
discount.expiry = new Date();
discount.expiry.setDate(Date.now() + 1);

答案 1 :(得分:0)

discount.expiry = new Date();
        discount.expiry.setDate(discount.expiry.getDate() + 1); 

希望这对您有帮助