zoukankan      html  css  js  c++  java
  • npm的qs包的使用:stringify()将json对象序列化成表单数据

      console.log(Qs.stringify({id: link, key: secretKey}))输入结果格式;url编码后的

      id=64d478c0-3904-11ea-a21e-fdd8236927e9&key=73QjHap%2BX0SR6Erqs%2F4BLQ%3D%3D

    import Qs from 'qs'
    // 。。。
    confirm = e => { let secretKey = this.contentSecretKeyInput.state.value secretKey = AESUtils.encryption(secretKey, config.frontSecretKey) let { link } = this.state link = link.substring(link.lastIndexOf('/') + 1) console.log(Qs.stringify({id: link, key: secretKey})) Axios.get('/api/encryption?' + Qs.stringify({id: link, key: secretKey})).then(res => { if (res.data.code === 0) { let content = res.data.data.content this.setState({ content }) // destroy dialog this.state.modal.destroy(); //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('guestdecrypt-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); } }) }

    ---

    buttonClickHandler = () => {
        let { content, pwd } = this.state
        content = AESUtils.encryption(content, config.frontSecretKey)
        pwd = AESUtils.encryption(pwd, config.frontSecretKey)
        const status = 0 // 0: normal
        const obj = { content, pwd, status }
        console.log(Qs.stringify(obj))
        Axios.post('/api/encryption', Qs.stringify(obj), { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }).then(res => {
            //console.log(res)
            //console.log("res.data.code=" + res.data.code)
            if (res.data.code === 0) {
                // console.log(res.data.data)
                //message.success('Successful');
                const postResult = res.data.data
                const url = config.baseLink + postResult.id
                this.setState({ postResult, url })
    
                const modal = Modal.confirm({
                    title: 'Resource Link',
                    icon: <Icon type="info-circle" />,
                    // content: <Input placeholder="Please Input the Secret Key" ref={input => this.contentSecretKeyInput = input} />,
                    content: (
                        <div>
                            <span className='encry-link-tip'>Resources are only saved for 5 minutes.</span>
                            <Input value={this.state.url} ref={input => this.urlInput = input} />
                        </div>
                    ),
                    okText: 'Copy',
                    cancelText: 'Close',
                    onOk: e => this.copyToClipboard(e)
                })
                this.setState({modal})
            } else {
                message.error(res.data.message);
            }
        })
    
    }

    ---

  • 相关阅读:
    2018前端越来越流行的的技术
    程序员怎么写出一份漂亮的简历
    程序员怎么写出一份漂亮的简历
    程序员如何利用空闲时间挣零花钱
    扫雷(mine)
    一道数论好题(math)
    消失的数字(number)
    1380 没有上司的舞会 40分
    2596 售货员的难题 水深搜
    JavaEE Tutorials (17)
  • 原文地址:https://www.cnblogs.com/xy-ouyang/p/12206560.html
Copyright © 2011-2022 走看看