我想从一个圣经api中获取数据。
示例:
https://kingjames.herokuapp.com/api/bible/Genesis/1/ https://kingjames.herokuapp.com/api/bible/Revelation/1/14
我可以用params id修改章节和诗句。但这本书行不通。我是否需要为这本书添加params.id以外的其他内容,因为它是文本而不是数字?
<template>
<div class="container">
<div v-for="verse in verses" :key="verse.id">
<p>{{ verse.Book + ' ' + verse.Chapter +':' + verse.Verse + ' ' + verse.Text }}</p>
</div>
</div>
</template>
<script>
import axios from "axios";
export default {
asyncData({ params, error }) {
return axios
.get(
`https://kingjames.herokuapp.com/api/bible/${params.id}/${params.id}/${params.id}`
)
.then(res => {
console.log(res.data);
return { verses: res.data };
});
}
};
</script>
发布于 2019-09-01 21:53:54
你需要传入3个不同的变量。您当前只传递了三次params.id,因此如果params.id =1,则结果URL将为
https://kingjames.herokuapp.com/api/bible/1/1/1
它至少会返回一个404。要正确使用它,您需要提供3个参数,其中2个是数字,一个是文本。
因此,参数应该类似于:
{章节: 1,经文: 1,书:‘路加福音’}
然后,您可以访问每个URL来创建URL。
https://kingjames.herokuapp.com/api/bible/${params.book}/${params.chapter}/${params.verse}
https://stackoverflow.com/questions/57749727
复制相似问题