Return 在控制器 AdonisJS 中查看

Return view in controller AdonisJS

如何return 视图并通过 AdonisJs 中的控制器显示它

'use strict'

class PostController {

  index(){
    return view.render('welcome')
  }

}

module.exports = PostController

报告此错误:

ReferenceError
view is not defined

您可以使用response.send(view.render('<your_view>'))

类似于:

...
index({ response, view }){ // Get objects from HTTP Context
  return response.send(view.render('welcome'))
}

HTTP Context documentation

Official forum answer

我知道来晚了,但这对我有用。

'use strict'

class PostController {

  async index({request,response,view}){
    return view.render('welcome')
  }

}

module.exports = PostController