antd踩坑:value.locale is not a function


這個問題來源於日期選擇器 RangerPicker 的特殊情況。

                            <Col span={7} key={9}>
                                <FormItem label="投運時間" {...formItemLayout2}>
                                    {getFieldDecorator('tysj', {
                                        initialValue: [undefined, moment().endOf('month')],
                                        rules: [
                                            {
                                                required: false,
                                                message: '投運時間!',
                                            },
                                        ],
                                    })(<RangerPicker style={{ width:'100%'}} format="YYYY-MM-DD" allowClear={true} />)}
                                </FormItem>
                            </Col>

有時我們希望默認值一邊有范圍,一邊沒有范圍。

比如 幾月幾號之前。

那么在表單賦值的時候,原先寫的是:

initialValue: ['', moment().endOf('month')],

但是這樣會導致清除時報錯:

value.locale is not a function

而只要改成:

initialValue: [undefined, moment().endOf('month')],

就可以了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM