美文网首页
请求封装

请求封装

作者: ticktackkk | 来源:发表于2021-01-15 14:00 被阅读0次
    import React, { useState, useRef, useEffect } from 'react';
    function App() {
    
        const [value, setValue] = useState(null)
        const [values, setValues] = useState(null)
        const [balance, setBalance] = useState(null)
    
        useEffect(() => {
            requestMap()
        }, [])
        const requestMap = () => {
            let requestMap = [
                { url: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', successFun: setValue },
                { url: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', successFun: setValues },
                { url: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', data: { Type: 'text' }, successFun: setBalance },
            ]
            requestMap.map(({ url, data, successFun }) => {
                request({
                    url,
                    data,
                    success: successFun
                })
            })
        }
    }
    export default App
    

    相关文章

      网友评论

          本文标题:请求封装

          本文链接:https://www.haomeiwen.com/subject/cmfwaktx.html