返回示例
单条随机返回格式:
{
"code": 200,
"category": "pc",
"count": 1,
"data": {
"id": "example",
"link": "https://t.xianyusss.top/img/example.webp"
}
}
多条随机返回格式(data 为数组):
{
"code": 200,
"category": "pc",
"count": 3,
"data": [
{ "id": "001", "link": "https://t.xianyusss.top/img/001.webp", "category": "pc" },
{ "id": "002", "link": "https://t.xianyusss.top/img/002.webp", "category": "pc" },
{ "id": "003", "link": "https://t.xianyusss.top/img/003.webp", "category": "pc" }
]
}
前端调用示例
JavaScript fetch 方式:
fetch('/json?pc')
.then(r => r.json())
.then(res => {
console.log(res.data.link);
// 直接用在 img 标签上
// img.src = res.data.link;
});
HTML 直接引用(最简单):
<img src="/pc" alt="随机图片">