Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
E
egg-example
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shangbj
egg-example
Commits
8ef156cd
Commit
8ef156cd
authored
Sep 26, 2018
by
shangbj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
抓去真实数据
parent
e187afa7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
6 deletions
+20
-6
news.js
app/controller/news.js
+3
-2
news.js
app/service/news.js
+7
-2
news.ejs
app/view/news.ejs
+8
-2
config.default.js
config/config.default.js
+2
-0
No files found.
app/controller/news.js
View file @
8ef156cd
...
...
@@ -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
,
});
}
...
...
app/service/news.js
View file @
8ef156cd
...
...
@@ -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
;
}
}
...
...
app/view/news.ejs
View file @
8ef156cd
...
...
@@ -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>
...
...
config/config.default.js
View file @
8ef156cd
...
...
@@ -16,5 +16,7 @@ module.exports = appInfo => {
},
};
config
.
api
=
'https://club.m.autohome.com.cn'
;
return
config
;
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment