• 解决antd design的Modal组件弹出卡顿的问题


    代码:

    import React from 'react'
    import ReactDOM from 'react-dom'
    import Axios from "axios";
    import copy from 'copy-to-clipboard'
    import { Input, Button, Modal, message, Icon } from 'antd'
    import '../static/css/input.css'
    import '../static/css/button.css'
    import '../static/css/modal.css'
    import '../static/css/message.css'
    import '../static/css/icon.css'
    import '../static/css/decrypt.css'
    
    const { TextArea } = Input;
    
    export default class Decrypt extends React.Component {
        state = {
            link: '',
            secretKey: '',
            content: ''
        }
    
        render() {
            return (
                <div id="decrypt-container" className='decrypt-container'>
                    <table className='decry-table'>
                        <tbody>
                        <tr>
                            <td><Input placeholder="Please Input the Link" onChange={e => this.linkInputChangehandler(e)} /></td>
                            <td><Button type="primary" onClick={this.buttonClickHandler}>Confirm</Button></td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            )
        }
    
        linkInputChangehandler = e => {
            const link = e.target.value
            this.setState({ link })
        }
    
        buttonClickHandler = () => {
            Modal.confirm({
                title: 'Resource extraction',
                icon: <Icon type="info-circle" />,
                content: <Input placeholder="Please Input the Secret Key" ref={input => this.contentSecretKeyInput = input} />,
                okText: 'Confirm',
                cancelText: 'Cannel',
                onOk: this.confirm
            })
        }
    
    
        confirm = () => {
            const secretKey = this.contentSecretKeyInput.state.value
            let { link } = this.state
            link = link.substring(link.lastIndexOf('/') + 1)
            // console.log(`secretKey=${secretKey}, link=${link}`)
    
            Axios.get('/api/encryption?id=' + link + '&key=' + secretKey).then(res => {
                if (res.data.code === 0) {
                    let content = res.data.data.content
                    this.setState({ content })
                    //message.success('Successful');
                    ReactDOM.render(
                        <div>
                            <span className='content-info'>The content you extract is:</span>
                            <TextArea rows={8} value={this.state.content} />
                            <Button className='copy-button' type="primary" onClick={this.buttonCopyHandler}>Copy</Button>
                        </div>,
                        document.getElementById('decrypt-container'),
                    );
                } else {
                    // error message info
                    if (res.data.data && res.data.data.incr)
                        message.error(`${res.data.message}, only ${res.data.data.incr} input opportunities left`);
                    else
                        message.error(res.data.message);
                }
            })
        }
    
        buttonCopyHandler = () => {
            // Get the value of the `value` attribute of the <Input> component
            copy(this.state.content)
        }
    
    }

    解决方案1:

      将导入antd组件css样式的代码删除,改为;

    import "antd/dist/antd.css"
    // import '../static/css/input.css'
    // import '../static/css/button.css'
    // import '../static/css/modal.css'
    // import '../static/css/message.css'
    // import '../static/css/icon.css'
    import '../static/css/decrypt.css'

      但是这样不能实现按需导入,加载了全部的 antd 组件的样式(gzipped 后一共大约 60kb)。

    解决方案1:按需导入antd组件css样式

      参考 https://ant.design/docs/react/use-with-create-react-app-cn

  • 相关阅读:
    C++如何对接sqlitepp
    c++11中的condition_variable和之前的pthread_cond_timedwait的不同之处
    浏览器设置代理模式后的报文是怎么样的?
    C++11中令人吐血的"移动语义"和"新的右值引用"
    MYSQL的事务及锁操作
    Microsoft Word —— 使用宏脚本将所有表格添加边框
    Navicat——如何导出数据字典
    Redis——配置详解
    keepalived——tengine集群主备均有VIP
    Docker——如何修改运行中容器的映射端口
  • 原文地址:https://www.cnblogs.com/xy-ouyang/p/12191354.html
Copyright © 2020-2023  润新知