建议看看这个链接: https://www.jianshu.com/p/7e1b057b047c/
- package.json加上这么一段 // 已经被证实,本地文档这一步不用做
"apidoc": {
"title": "接口文档",
"url": "http://localhost:256"
}
- 项目根目录下创建apidoc.json, 内容为
{
"name": "接口文档",
"version": "1.0.0",
"description": "腾讯云服务器接口文档",
"title": "接口文档",
"url" : "http://localhost:3000"
}
- 这里是express接口,在router.get上方加接口注释,示例如下
/**
* @api {get} /focus/getfocus 获取焦点图
* @apiDescription 获取焦点图
* @apiName getfocus
* @apiGroup focus
* @apiSuccess {json} result
* @apiSuccessExample {json} Success-Response:
* [
* {
* "imsrc": "C:\\Users\\goodDream\\Desktop\\shujuku\\服务器文件/public/images/banner/_20200424170643.jpg"
* },
* {
* "imsrc": "C:\\Users\\goodDream\\Desktop\\shujuku\\服务器文件/public/images/banner/_20200424170649.jpg"
* },
* {
* "imsrc": "C:\\Users\\goodDream\\Desktop\\shujuku\\服务器文件/public/images/banner/_20200424170655.jpg"
* }
* ]
* @apiSampleRequest http://localhost:256/focus/getfocus
* @apiVersion 1.0.0
*/
- 每次修改接口都需要在控制台执行这一句
apidoc -i router/ -o public/apidoc/
router/ 接口所在的位置(我这里放的全是二级路由)
public/apidoc/ 是生成接口文件的目录
- 运行后台, 访问接口文档地址 http://localhost:256/apidoc/index.html(本地直接打开该文件)
如果一直加载中,参考这个文章https://blog.csdn.net/leedaning/article/details/51066358?utm_source=blogxgwz7