Commit 8ef156cd authored by shangbj's avatar shangbj

抓去真实数据

parent e187afa7
......@@ -5,9 +5,10 @@ const Controller = require('egg').Controller;
class NewsController extends Controller {
async index() {
// this.ctx.body = '你好新闻';
const msg = await this.service.news.getNewsList();
const list = await this.service.news.getNewsList();
await this.ctx.render('news.ejs', {
msg,
list,
});
}
......
......@@ -4,8 +4,13 @@ const Service = require('egg').Service;
class NewsService extends Service {
async getNewsList() {
const title = 'hahahaha';
return title;
// 抓数据curl获取远程数据
const url = `${this.config.api}/adaptive/home/GetLatestHotTopics_2018?pageIndex=1&pageSize=90&classid=-1&tag=true&isappend=false`;
const res = await this.ctx.curl(url);
const data = JSON.parse(res.data);
return data.List;
}
}
......
......@@ -9,9 +9,15 @@
</head>
<body>
<h2>新闻页面-
<%=msg%>
<h2>新闻页面-列表
</h2>
<ul>
<%for(var i=0;i<list.length;i++){%>
<li>
<%=list[i].title%>
</li>
<%}%>
</ul>
<img src="/public/images/1.jpg" />
</body>
......
......@@ -16,5 +16,7 @@ module.exports = appInfo => {
},
};
config.api = 'https://club.m.autohome.com.cn';
return config;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment