Как запустить GET-запрос для цикла с vueJS? - PullRequest
0 голосов
/ 25 октября 2018

Я хочу заполнить вызовы GET REST из приложения vuejs.

В настоящее время у меня есть следующий шаблон

<template>
<div class="app-container">
  <div class="currentjob">
    <h1>Current Jobs</h1>
    <table>
      <tr>
        <th>ID</th>
        <th>Status</th>
        <th>AlgorithmID</th>
        <th>Result</th>
      </tr>
      <tr v-for="job in jobs">
        <td>{{ job.id }}</td>
        <td>{{ job.status }}</td>
        <td>{{ job.algorithmId }}</td>
        <td>{{ getResult(job.id) }}</td>
      </tr>
    </table>
  </div>
</div>
</template>

<script>
    export default
    {
        name: 'CurrentJobs',
        data()
        {
            return {
                jobs: null
            }
        },
        mounted()
        {
            this.$axios
                .get(this.$baseUrl + 'job')
                .then(response => (this.jobs = response.data))
        },
        methods:
        {
            getResult: function(jobid)
            {
                  this.$axios.get(this.$baseUrl + 'job/result/'+jobid).
                    then(response =>
                      {
                       return response.data // does not work 
                      }) 
            }
        }
    }
</script>

Обычно я могу выполнить запрос GET следующим образом

this.$axios.
  get(this.$baseUrl + 'job/result/'+jobid).
  then(response =>
    {
     // return response.data // does not work 
    }
  ) 

Но я не могу добавить оператор возврата вфункция стрелки внутри метода then.Как я могу вернуть ответ на вызов REST?Какую основную концепцию мне не хватает?

Ответы [ 2 ]

0 голосов
/ 25 октября 2018

Возвращайте ваш axios результат при вызове этого.

Пример:

getResult: function(jobid)
     {
       return this.$axios.get(this.$baseUrl + 'job/result/'+jobid).
        then(response =>
        {
            return response.data
        })
     }
0 голосов
/ 25 октября 2018

попробуйте это:

this.$axios.
get(this.$baseUrl + 'job/result/'+jobid).
then(response =>
{
 this.jobs = response.data 
}
) 

, делая это, вы передаете ответ на ваши jobs данные

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...