为了在 Antd 模态框中使用样式 API,需要添加以下样式:
.ant-modal-wrap { .ant-modal { .ant-modal-content { // add your styles here } } }
示例:
import React from 'react'; import { Modal, Button } from 'antd';
const MyModal = () => {
return (
Some modal content...
); }export default function App() { return (
// Style for the modal content const modalContentStyle = { background: 'red', color: 'white', };
// Style added to make the Antd modal style API work
const antdModalWrapStyle = .ant-modal-wrap { .ant-modal { .ant-modal-content { ${Object.keys(modalContentStyle).map(k =>
${k}: ${modalContentStyle[k]}).join(';')} } } }
;
document.head.insertAdjacentHTML('beforeend', );