diff --git a/src/components/cards/Card.ts b/src/components/cards/Card.ts index a3dc981..b2b931f 100644 --- a/src/components/cards/Card.ts +++ b/src/components/cards/Card.ts @@ -1,5 +1,7 @@ // import axios from "axios"; +import FetchWrapper from "../utils/FetchWapper"; + export const schema = [ { name: 'title', label: '标题', type: 'input' }, { name: 'body', label: '内容', type: 'input' }, @@ -18,7 +20,34 @@ export type cardType = { btnHref?: string | null }; -function getData() { +export function getDatas(url: string, cards: cardType[]) { + console.log(url); + FetchWrapper.fetch(url, { timeout: 3000 }) + .then(response => { + if (!response.ok) { + // throw new Error(`HTTP error! status: ${response.status}`); + return null; + } + console.log(response); + return response.json(); + }).then(jsonData => { + console.log('JSON Data:', jsonData); + if (!jsonData) { + return null; + } + cards.length = 0; + jsonData.datas.forEach((i: cardType) => { + const item = { ...jsonData.default_item, ...i } + cards.push({ + title: item.title, + body: item.intro, + jumpHerf: item.url + }) + }) + }) + .catch(error => { + console.error('Error fetching data:', error); + }); } function setData() { diff --git a/src/components/utils/IFrame.vue b/src/components/utils/IFrame.vue index 1c3671f..99fdf19 100644 --- a/src/components/utils/IFrame.vue +++ b/src/components/utils/IFrame.vue @@ -1,6 +1,6 @@