案例-新闻列表
1. 实现步骤
① 获取新闻数据
② 定义 template 模板
③ 编译模板
④ 定义时间过滤器
⑤ 定义补零函数
新闻列表接口文档
请求的根路径
http://www.liulongbin.top:3006
新闻列表
- 接口URL: /api/news
- 调用方式: GET
- 参数格式:无
- 响应格式:
- 返回示例:
{
"status": 200,
"msg": "获取新闻列表成功",
"data": [
{
"id": 1,
"title": "5G商用在即,三大运营商营收持续下降",
"source": "新京报经济新闻",
"cmtcount": 58,
"tags": "三大运营商,中国移动,5G商用",
"img": "/images/0.webp",
"time": "2019-10-28T03:50:28.000Z"
}
]
}
实现代码:
html文件:
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<link rel="stylesheet" href="./assets/news.css" />
<script src="./lib/jquery.js"></script>
<script src="./lib/template-web.js">