1.0.4 • Published 12 months ago

dpp-w v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

const username1 = document.querySelector('.username') const password1 = document.querySelector('.password') // function fn(){ // axiosPost('http://localhost:3000/maomi',{username:username1.value,password:password1.value}).then(res=>{ // console.log(res); // }) // }

function fn(){
    let obj={
        username:username1.value,
        password:password1.value
    }
    axios.post('/maomi',obj).then(res=>{
        console.log(res);
    })
}
function log(params){
    let obj={
        username:username1.value,
        password:password1.value
    }
    axios.post('/maotouying',obj).then(res=>{
        console.log(res);
        // if(res.data.token){
        //     localStorage.setItem('token',res.data.token)
        //     document.querySelector('.div').innerHTML=res.data.token
        // }
    })
}

二 // 添加请求拦截器 axios.interceptors.request.use(function (config) { // 在发送请求之前做些什么 return config; }, function (error) { // 对请求错误做些什么 return Promise.reject(error); });

// 添加响应拦截器 axios.interceptors.response.use(function (response) { // 对响应数据做点什么 return response; }, function (error) { // 对响应错误做点什么 return Promise.reject(error); });

三 function axiosGet(URL, params) { return new Promise((resolve, reject) => { // 为给定 ID 的 user 创建请求 axios.get(URL, { params }).then(function (response) { resolve(response); }).catch(function (error) { reject(error); }); })

}

function axiosPost(URL, params) { return new Promise((resolve, reject) => { // 为给定 ID 的 user 创建请求 axios.post(URL, params).then(function (response) { resolve(response); }).catch(function (error) { reject(error); }); })

}