<Form.Item label="推送" name="top">
<Switch defaultChecked checkedChildren={<CheckOutlined />} unCheckedChildren={<CloseOutlined />} />
</Form.Item>
點(diǎn)擊提交按鈕提交開關(guān)的表單值top為undefined
解決方法:
需添加valuePropName="checked"反惕,并設(shè)置默認(rèn)值 initialValue
<Form.Item label="推送" name="top" valuePropName="checked" initialValue={true} >
<Switch defaultChecked checkedChildren={<CheckOutlined />} unCheckedChildren={<CloseOutlined />} />
</Form.Item>
p.s:
如果設(shè)置initialValue無效,則為form設(shè)置默認(rèn)值