## 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
~~~