## 1. this.ctx.query获取get传值
~~~
class NewsController extends Controller {
async index() {
this.ctx.body = "这是新闻页面"
}
async content() {
const {ctx} = this;
console.log(ctx.query)
this.ctx.body = "新闻详情"
}
}
~~~
## 2 this.ctx.params获取动态路由
~~~
//配置动态路由
router.get('/newslist/:id',controller.news.newslist)
~~~
~~~
//获取动态路由
class NewsController extends Controller {
async index() {
this.ctx.body = "这是新闻页面"
}
async newslist(){
console.log(this.ctx.params)
this.ctx.body = "新闻列表"
}
}
~~~
## 3.静态资源的使用
~~~
<img src="/public/images/print.png" alt="">
~~~
### 4.获取ip
~~~
ctx.request.ip
~~~