koa2 ctx.request.query ist nicht definiert, wenn ich eine Ajax-Anfrage mache, aber es funktioniert gut, wenn ich diese "Post" mache Anfrage im Postboten.koa2 ctx.request.query ist nicht definiert, wenn ich eine Ajax-Anfrage mache, aber im Postboten funktioniert es gut
In Postbote kann ich die Abfrage Objekt erhalten enter image description here
Aber durch axios enter image description here
Meine Anfrage Code ist
<template>
<div id="login">
<mt-field label="用户名" placeholder="请输入用户名" v-model="username"></mt-field>
<mt-field label="密码" placeholder="请输入密码" type="password" v-model="password"></mt-field>
<mt-button type="primary" @click="login">primary</mt-button>
</div>
</template>
<script>
import Axios from 'axios'
export default {
name: 'login',
data() {
return {
username: '',
password: ''
}
},
mounted(){
console.log(Axios)
},
methods: {
login(){
var username = this.username;
var password = this.password;
Axios({
method: 'post',
url: "api/user/login",
data: {
username: username,
password: password,
},
}).then((res)=>{
console.log(res)
if(res.data.code !== 200) {
console.log("登录失败")
}
});
}
}
}
</script>
Backend:
'POST /api/user/login': async (ctx, next) => {
ctx.response.type = 'application/json;charset=utf-8';
console.log(ctx.request.query)
await Db.User.login(ctx.query)
.then(function(res){
ctx.response.body = res
});
}
Ich denke, es gibt ein Problem in koa2 ctx.request.query ist, wenn es nur bestimmte 'Form' erhalten