如何从发布请求中打印响应

我正在尝试为与我输入的单词匹配的日托制作一个简单的搜索栏,我向api发送发布请求,然后取回与我键入的内容匹配的所有日托,这是我的代码:

<template>
  <div class="body">
    <div>
    <h1 class="mt-3">Busca una guarderia</h1>
    <div class=" mx-1 mb-5">
    <b-form @submit.prevent="buscarGuarderia">    
    <b-form-group id="input-group-1" label-for="input-1">
          <b-form-input
            id="input-1"  
            v-model="cadena"
            required          
          >          
          </b-form-input>
        </b-form-group>
    <div class="mt-2">
    </div>
    <b-button block pill type="submit" variant="success">
        Buscar
    </b-button>
    </b-form>
  </div>
  </div>
  </div>
</template>

<script>
import { mapState } from 'vuex';
export default {
  name: "SearchDaycare",
  data() {
    return {
    currentUser: {},
    cadena: ""
    }
  },
  computed: {
    ...mapState(["daycares"]),
  },
  methods: { 
      getDaycare(){
      this.$store.dispatch("getDogDayCares", {
          user: this.currentUser.user
          });
    },
      buscarGuarderia() {      
      this.$store.dispatch("buscarGuarderia", [{
        cadena: this.cadena,
      }, "clients"])
      .then();
    }
  },
    created() {
        if (localStorage.getItem("user")) {
        try {
            this.currentUser = JSON.parse(localStorage.getItem("user"));
        } catch (e) {
            localStorage.removeItem("user");
            }
        }
    }

};
</script>
<style lang="scss" scoped>
h1 {
  color: #40db9a;
}
.body {
  margin: 0;
  height: auto;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.cards {
  display: flex;
}
.card {
  color: #063869;
  background-color: #eef6e1;
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: 3px 3px 12px 2px rgba(black, 0.6);
  transition: 0.2s;
}
.card:not(:first-child) {
  margin-left: -2rem;
}
.card:not(:last-child):hover,
.card:not(:last-child):focus-within {
  transform: translateY(-1rem);
  ~ .card {
    transform: translateX(2rem);
  }
}
</style>

这是buscarGuarderia函数,它是将请求发送到API的函数

buscarGuarderia({ commit }, [credentials, userClass]) {
  return axios.post("/api/" + userClass + "/searchdaycarebyname", credentials).then();
}

It works fine, I send the post request and get a response from the API, what I want to do is print the response or responses that I get, I'm having trouble doing this, any help would be appreciated here's an image of the response

评论
  • 胡图图
    胡图图 回复

    Inside then you can fill the sucess response:

    buscarGuarderia({ commit }, [credentials, userClass]) {
      return axios.post("/api/" + userClass + "/searchdaycarebyname", credentials)
                  .then(function(response){
                      console.log(response.data)
                   });
    }