簡體   English   中英

打包電子應用程序后出現無效的日期錯誤

[英]Invalid Date error after packaging an electron app

我已經用Electron編寫了一個應用程序,一切都在開發環境中工作。

但是在electron-packager之后,我有無效的日期...

import React, { Component, PropTypes } from 'react';
import moment from 'moment';

[...]

render() {
    const { code } = this.props;

    moment.locale('fr');

    return (
        <div className="ViewCode">
            <header>
                { code.code }
                <span style={{flex: 1}}></span>
                <i className="fa fa-pencil-square-o"></i>
                <i className="fa fa-trash" onClick={this.handleDelete.bind(this)}></i>
            </header>
            <article>
                <div>Name { code.code }</div>
                <div>Expiration Date { moment(code.expirationDate).format('LLLL') }</div>
                <div>Max use { code.maxUse }</div>
                <div>Max use by user { code.maxUseByUser }</div>
                <div>Action { code.action }</div>
                <div>Number of use { code.users.length }</div>
            </article>
        </div>
    )

}

}

包裝前: jeudi 31 décembre 2015 00:59

包裝后: Invalid Date

任何想法?

看起來code.expirationDate不是日期對象,您可以檢查其生命周期。 或者,如果沒有有效日期,則僅顯示其他內容:

render() {

    const { code } = this.props;

    moment.locale('fr');

    if(!code.expirationDate instanceof Date) {

        return <div>something</div>;

    } else {

        return (
            <div className="ViewCode">
                <header>
                    { code.code }
                    <span style={{flex: 1}}></span>
                    <i className="fa fa-pencil-square-o"></i>
                    <i className="fa fa-trash" onClick={this.handleDelete.bind(this)}></i>
                </header>
                <article>
                    <div>Name { code.code }</div>
                    <div>Expiration Date { moment(code.expirationDate).format('LLLL') }</div>
                    <div>Max use { code.maxUse }</div>
                    <div>Max use by user { code.maxUseByUser }</div>
                    <div>Action { code.action }</div>
                    <div>Number of use { code.users.length }</div>
                </article>
            </div>
        );
    }
}

不要猶豫,使用BrowserWindow.openDevTools()console.log來幫助您調試此類錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM