Tuesday, 25 April 2017

koa2 ctx.request.query is not defined when I make an ajax request

koa2 ctx.request.query is not defined when I make an ajax request but It works fine when I make this 'post' request in postman.

In postman I can get the query object enter image description here

But through axios enter image description here

My request code is

<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>

I think there is some problem in koa2 ctx.request.query, if it only receive specific 'form'



via user6542007

No comments:

Post a Comment