在我的导航中,我想从我的 CMS 中插入链接。我正在使用 Axios。我的导航是 Vue。如何将 JSON 文件中的数据获取到 const 中?
只要知道我是否需要在 Axios 或 Vue 中搜索解决方案也会有很大帮助。
import axios from "axios";
const exhibitions = [
{
name: "Exhibition 1",
description: "Info 1",
href: "#",
},
{
name: "Exhibition 2",
description: "Info 2",
href: "#",
},
];
我的导出默认值:
export default {
name: "item",
data() {
return {
info: null,
};
},
mounted() {
axios
.get("http://localhost:8000/posts.json")
.then((response) => (this.info = response));
},
帖子.json
{
"data":
[{
"id":1028,
"title":"Exhibition 1",
"slug":"exhibition-2009",
"url":"http://localhost:8000/exhibitions/exhibition-2009"
},
{
"id":905,
"title":"Exhibition 2",
"slug":"exhibition-2006",
"url":"http://localhost:8000/exhibitions/exhibition-2006"
}],
"meta":
{
"pagination":
{
"total":2,
"count":2,
"per_page":100,
"current_page":1,
"total_pages":1,
"links":{}
}
}
}