axios

axios({
url: 'https://garen.xiaoxinyong.com/v1/user/login',
method: 'post',
data: sub(dilo),
transformRequest: [function(data) {

                        let ret = ''
                        for(let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        ret = ret.slice(0, -1)
                        console.log(ret)
                        return ret
                    }],
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                }).then((res) => {
                    if(res.data.errno == 200) {

// var router = new Router()
// router.replace({
// path:'/index'
//
// });

                        window.localStorage.setItem('uid',res.data.data.userid)
                        window.localStorage.setItem('name',res.data.data.name)
                        window.localStorage.setItem('phone',res.data.data.phone)
                        window.localStorage.setItem('headImg',res.data.data.headimg)

// console.log(uid,name,phone,headImg);

                         newRouter.push({path:'/index'})
                    
                    }
                    if(res.data.errno == 400) {
                        fin();
                        box.innerHTML = res.data.errmsg
                    }
                    console.log(res.data.errno)
                }).catch((err) => {
                    console.log(err)
                    fin();
                    box.innerHTML = "登录失败"
                })

            }

你可能感兴趣的:(axios)