Vue axios encapsulation problem

1 / axios.js file

export function post(url,data){
    return new Promise((resolve,reject) => {    
        axios.post(url,data)
        .then(response => {
            resolve(response.data);
        },err => {
            reject(err)
        }).catch(err => {
            reject(err.data)
        })
    })
}

2 / login.vue file

methods: {
            submitForm(formName){
                this.$refs[formName].validate((valid) => {
                    if(valid) {
                        this.post("",{
                            username: this.loginForm.username,
                            password: this.loginForm.password 
                        })
                        .then( res=>{
                            console.log(res)
                        })
                    }else{
                        console.log("Error Submit!!")
                    }
                })
            }
        },
< hr >

Why the login result is

clipboard.png


:.

clipboard.png

< hr >

what is the problem? How should we solve this problem?

Mar.03,2022

the default parameter passed by axios is assigned under params, while post is the

to be received by data.
this.$axios({
    method: 'post',
    url:url,
    data:params
}).then((res)=>{
    
});

modify request header 'Content-Type': application/json;charset=UTF-8

Menu