Commit 8ef156cd authored by shangbj's avatar shangbj

抓去真实数据

parent e187afa7
...@@ -5,9 +5,10 @@ const Controller = require('egg').Controller; ...@@ -5,9 +5,10 @@ const Controller = require('egg').Controller;
class NewsController extends Controller { class NewsController extends Controller {
async index() { async index() {
// this.ctx.body = '你好新闻'; // this.ctx.body = '你好新闻';
const msg = await this.service.news.getNewsList(); const list = await this.service.news.getNewsList();
await this.ctx.render('news.ejs', { await this.ctx.render('news.ejs', {
msg, list,
}); });
} }
......
...@@ -4,8 +4,13 @@ const Service = require('egg').Service; ...@@ -4,8 +4,13 @@ const Service = require('egg').Service;
class NewsService extends Service { class NewsService extends Service {
async getNewsList() { async getNewsList() {
const title = 'hahahaha'; // 抓数据curl获取远程数据
return title; 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 @@ ...@@ -9,9 +9,15 @@
</head> </head>
<body> <body>
<h2>新闻页面- <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" /> <img src="/public/images/1.jpg" />
</body> </body>
......
...@@ -16,5 +16,7 @@ module.exports = appInfo => { ...@@ -16,5 +16,7 @@ module.exports = appInfo => {
}, },
}; };
config.api = 'https://club.m.autohome.com.cn';
return config; 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