【发布时间】:2018-01-24 09:31:03
【问题描述】:
在我的 nuxt 应用程序中,我需要像这样调用外部 api (file.vue):
<template>
<div class="container">
<h1>{{ post.title }}</h1>
<pre>{{ post.body }}</pre>
<p><nuxt-link to="/posts">Back to the list</nuxt-link></p>
</div>
</template>
<script>
export default {
async asyncData({ app }) {
let { data } = await app.$axios.$get(`http://my.api.adress:8001/competition/sport/4?_format=json&limit=20&offset=0`)
return { post: data }
},
head() {
return {
title: this.post.title
}
}
}
</script>
为了使这个调用有效,我需要将树参数传递给我的标题。任何人都知道如何做到这一点以使其适用于 nuxt 中的所有 api 调用?
【问题讨论】:
标签: vuejs2 fetch axios nuxt.js