Closed spoem9527 closed 1 year ago
react-vant
react-vant-icons
3.1.1
No response
代码样例 import React, { useState, useEffect, useRef } from "react"; import { DatetimePicker, Field } from "react-vant"; const Demo = () => { const [value, setValue] = useState(null); return ( <DatetimePicker popup={{ round: true, }} type="date" title="选择年月日" minDate={new Date(2021, 0, 1)} maxDate={new Date(2025, 10, 1)} value={value} defaultValue={new Date()} onConfirm={setValue}
{(val, _, actions) => { return ( <Field readOnly clickable label="选择年月日" value={val} placeholder="请选择日期" onClick={() => actions.open()} /> ); }} ); };
export default Demo;
注意看图片中,默认选择的日期 设置了popup属性
没有设置popup属性
可能问题出现在DatePicker.js的154行const value = props.popup ? formatValue(props.value) : currentDateRef.current; 传递给formatValue的值没有defaultValue 应该参照 DatePicker.js的33行const [currentDate, setCurrentDate, currentDateRef] = useRefState(() => formatValue(value || defaultValue)) 这样给formatValue传值
Which React Vant packages are impacted?
react-vant
(React Vant core)react-vant-icons
(React Vant Icon)What version of React Vant are you using?
3.1.1
Reproduce live demo(codesandebox or stackblitz)?
No response
Descripition
代码样例 import React, { useState, useEffect, useRef } from "react"; import { DatetimePicker, Field } from "react-vant"; const Demo = () => { const [value, setValue] = useState(null); return ( <DatetimePicker popup={{ round: true, }} type="date" title="选择年月日" minDate={new Date(2021, 0, 1)} maxDate={new Date(2025, 10, 1)} value={value} defaultValue={new Date()} onConfirm={setValue}
export default Demo;
注意看图片中,默认选择的日期 设置了popup属性
没有设置popup属性
可能问题出现在DatePicker.js的154行const value = props.popup ? formatValue(props.value) : currentDateRef.current; 传递给formatValue的值没有defaultValue 应该参照 DatePicker.js的33行const [currentDate, setCurrentDate, currentDateRef] = useRefState(() => formatValue(value || defaultValue)) 这样给formatValue传值