我在使用Promise(??)使用VueJS,axios,Async / Await从REST-API检索数据时遇到问题。我需要调用两个不同的REST-API。一个是给我一张清单,我可以遍历它,这很好。
<template>
<div>
<div v-if="posts && posts.length">
<div v-for="post of posts">
{{post.name}}
<img :src="getUserPicturePath(post.name)" />
</div>
</div>
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
如您所见,另一种方法是在v-for之间,调用使用axios的方法。
<script>
import axios from 'axios'
export default {
data: () => {
posts: []
}
created() {
// a method to fill up the post-array
},
methods: {
async getUserPicturePath(name){
const response = await axios.get('linkToApi'+name)
console.dir(response.data.profilePicture.path)
return response.data.profilePicture.path
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
本console.dir(response.data.profilePicture.path)-部分是给正确的路径profilePicture,但<img :src="getUserPicturePath(post.name)" />在上面的<template>,写[Object Promise]。
有什么建议我怎么走吗?
我在检索潜在客户广告时遇到问题。
我有广告ID和页面ID。我还没有创建它们,但是被添加为开发人员。
我正在尝试使用PHP SDK和此https://developers.facebook.com/docs/marketing-api/guides/lead-ads/v2.9
什么都没用。我找不到关于它的不错的教程。我只想检索领先的广告!
任何人?