как использовать обещание в компоненте VUE - PullRequest
0 голосов
/ 17 декабря 2018

Это родительское Vue ниже:

<template>
<div id="app" class="">
<div class="wrapper">
  <!-- Page Content -->
  <div id="content">
   <div class="container-fluid"> 
      <b-container>
        <router-view
          :srcUrl="srcUrl" :responses="responses[activityIndex]"
          v-on:updateProgress="updateProgress"
          v-on:saveResponse="saveResponse"
        />
      </b-container>
  </div>
</div>

<script>
import jsonld from 'jsonld/dist/jsonld.min';
export default {
name: 'App',
data() {
 return {
  schema: {},
  activityIndex: null,
  responses: {},
};
},
watch: {
$route() {
  if (this.$route.params.id) {
    this.activityIndex = this.$route.params.id;
  }
},
},
mounted() {
axios.get(config.githubSrc).then((resp) => {
  this.schema = resp.data;
  this.progress = _.map(this.schema.ui.order, () => 0);
  this.responses = _.map(this.schema.ui.order, () => new Object());
  if (this.$route.params.id) {
    this.activityIndex = this.$route.params.id;
  }
});
},
computed: {
  srcUrl() {
    if (this.activityIndex) {
      jsonld.expand(this.schema, result => {
        return result;
      });
    }
    return null;
  },
}
};
</script>

Как мне использовать jsonld.expand в вычисляемом методе vue srcUrl, чтобы он возвращал что-то в дочернем vue?Насколько мне кажется, jsonld - это асинхронная функция.Следовательно, это не работает, когда я пишу это так.все, что я получаю в ребенке, это ожидающее обещание.

Как я могу решить это?

у ребенка vue есть это:

props: ['srcUrl', 'responses'],
watch: {
srcUrl() {
  if (this.srcUrl) {
    this.getData();
  }
},
},
mounted() {
if (this.srcUrl) {
  // eslint-disable-next-line
  console.log('Home mounted: ', this.srcUrl);
  this.getData();
}
},
};
</script>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...