Answer the question
In order to leave comments, you need to log in
How to pass the result of an asynchronous function to props?
Hi guys, I'm interested in the opinion of the community, how can I convey to
propsfrom App.js [root component] to child-component result of async function instead of prommise
<template>
<div id="app">
<imgMap v-bind:api="accessAPI"></imgMap>
</div>
</template>
<script>
import accessAPI from './js/api/api-v1'; // import api
export default {
name: 'app',
components: {
imgMap
},
data() {
return {
mapID: null,
api: null,
}
},
computed: {
accessAPI : function (){
return accessAPI()
}
}
<script>
Answer the question
In order to leave comments, you need to log in
Make a property where the data passed to the child component will be stored, and replace that strange thing with a computed property with a regular method. It will look something like this:
data: () => ({
apiData: null,
}),
methods: {
getAPIData() {
accessAPI().then(result => this.apiData = result);
},
},
created() {
this.getAPIData();
},
<imgMap :api="apiData"></imgMap>
<imgMap :api="apiData" v-if="apiData"></imgMap>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question