{"id":7564,"date":"2018-05-09T02:26:32","date_gmt":"2018-05-08T18:26:32","guid":{"rendered":"http:\/\/www.zhangxinxu.com\/wordpress\/?p=7564"},"modified":"2018-05-09T10:37:14","modified_gmt":"2018-05-09T02:37:14","slug":"introduce-yapi-api","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2018\/05\/introduce-yapi-api\/","title":{"rendered":"\u5728\u540c\u4e8b\u7684\u5b89\u5229\u4e0b\uff0c\u8bd5\u7528\u4e86\u4e0b\u63a5\u53e3\u7ba1\u7406\u5e73\u53f0YApi"},"content":{"rendered":"<p>by <a href=\"http:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=7564\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=7564<\/a><br \/>\n\u672c\u6587\u53ef\u5168\u6587\u8f6c\u8f7d\uff0c\u4f46\u9700\u8981\u4fdd\u7559\u539f\u4f5c\u8005\u548c\u51fa\u5904\u3002<\/p>\n<p>\u4e1a\u754c\u63a5\u53e3\u7ba1\u7406\u5e73\u53f0\u6709\u597d\u4e9b\u4e2a\uff0c\u4f8b\u5982<a href=\"https:\/\/www.easyapi.com\/\" rel=\"nofollow\" target=\"_blank\">easyapi<\/a>\uff0csosoapi\uff0c\u8fd8\u6709\u672c\u6587\u8981\u4ecb\u7ecd\u7684<a href=\"http:\/\/yapi.demo.qunar.com\/\" rel=\"noopener\" target=\"_blank\">YApi<\/a>\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-08_225209.png\" width=\"223\" height=\"108\" alt=\"YAPI\u7684logo\" class=\"alignnone\" \/><\/p>\n<p>\u7ad9\u5728\u56e2\u961f\u89d2\u5ea6\u8bb2\uff0c\u8fd9\u4e9b\u63a5\u53e3\u5e73\u53f0\u6700\u5927\u4f5c\u7528\u662f\u56e2\u961f\u5185\u90e8\u63a5\u5165\uff0c\u89c4\u8303API\uff0c\u7ba1\u7406\uff0c\u5408\u4f5c\u7b49\u90fd\u4f1a\u53d8\u5f97\u66f4\u52a0\u8f7b\u677e\u3002<\/p>\n<p>\u7ad9\u5728\u4e2a\u4eba\u89d2\u5ea6\u8bb2\uff0c\u5c24\u5176\u5bf9\u4e8e\u9700\u8981\u5199\u9ad8\u4fdd\u771f\u9875\u9762\u7684\u524d\u7aef\u91cd\u6784\u4eba\u5458\uff0c\u8fd9\u4e9b\u63a5\u53e3\u5e73\u53f0\u53ef\u4ee5\u6a21\u62df\u8fd4\u56de\u66f4\u52a0\u771f\u5b9e\u7684\u6570\u636e\uff0c\u5929\u7136\u8de8\u57df\u652f\u6301\uff0c\u81ea\u5df1\u65e0\u9700\u989d\u5916\u642d\u5efa\u670d\u52a1\uff0c\u5c31\u80fd\u6709\u52a8\u6001\u7279\u6027\u5c55\u793a\u3002<\/p>\n<p>\u81ea\u5df1\u7ecf\u5e38\u8981\u5199\u9ad8\u4fdd\u771f\u7684\u4ea4\u4e92\u539f\u578b\uff0c\u56e0\u6b64\uff0c\u9700\u8981\u53ef\u4ee5\u6709\u76f8\u5f53\u771f\u5b9e\u7684API\u8bf7\u6c42\u6570\u636e\uff0c\u4f8b\u5982\u51fa\u9519\uff0c\u8bf7\u6c42\u5ef6\u65f6\u6a21\u62df\uff0c\u6781\u7aef\u6570\u636e\u5904\u7406\u7b49\u3002\u540c\u4e8b\u7684\u5b89\u5229\u4e0b\uff0c\u5c31\u5f00\u59cb\u63a5\u89e6YApi\uff0c\u8bd5\u7528\u4e86\u4e0b\uff0c\u603b\u4f53\u8fd8\u884c\uff0c\u6709\u4e00\u4e9b\u5c0f\u5751\uff0c\u6709\u4e00\u4e9b\u5c40\u9650\uff0c\u8fd9\u91cc\u81ea\u5df1\u8bb0\u5f55\u4e0b\uff0c\u4ee5\u540e\u7528\u5f97\u5230\u3002<\/p>\n<h3>\u4e00\u3001\u63a5\u53e3\u7ba1\u7406\u5e73\u53f0YApi\u7b80\u4ecb<\/h3>\n<p>\u8fd9\u91cc\u7684\u4ecb\u7ecd\u4e3b\u8981\u7ad9\u5728\u4e2a\u4eba\u4f7f\u7528\u89d2\u5ea6\u800c\u8a00\u7684\u3002<\/p>\n<p>\u9996\u5148<a href=\"http:\/\/yapi.demo.qunar.com\/login\" rel=\"noopener\" target=\"_blank\">\u6ce8\u518c<\/a>\uff0c\u65e0\u9700\u90ae\u7bb1\u9a8c\u8bc1\u5c31\u53ef\u4ee5\u7528\u3002<\/p>\n<p>\u8fdb\u5165\u540e\u201c\u65b0\u5efa\u9879\u76ee\u201d\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_000928.png\" width=\"339\" height=\"243\" alt=\"\u6dfb\u52a0\u9879\u76ee\" class=\"alignnone\" \/><\/p>\n<p>\u968f\u4fbf\u586b\u4e00\u586b\uff0c\u9009\u4e00\u9009\uff0c\u6743\u9650\u53ef\u4ee5\u9009\u62e9\u516c\u5f00\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_001432.png\" width=\"485\" height=\"509\" alt=\"\u6743\u9650\u516c\u5f00\" class=\"alignnone\" \/><\/p>\n<p>\u7136\u540e\u5c31\u53ef\u4ee5\u6dfb\u52a0\u63a5\u53e3\u4e86\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_001630.png\" width=\"351\" height=\"250\" alt=\"\u6dfb\u52a0\u63a5\u53e3\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<p>\u8fd9\u91cc\u53ef\u4ee5\u968f\u610f\u70b9\uff0c\u53cd\u6b63\u540e\u671f\u53ef\u4ee5\u4fee\u6539\u7684\uff0c\u4f8b\u5982\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_002251.png\" width=\"527\" height=\"310\" alt=\"\u6dfb\u52a0\u63a5\u53e3\u5165\u53e3\" class=\"alignnone\" \/><\/p>\n<p>\u786e\u5b9a\u540e\u5c31\u8fdb\u5165\u4e0b\u56fe\u6240\u793a\u7684\u754c\u9762\uff0c\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>\u201c\u9884\u89c8\u201d\u4f5c\u7528\u5c31\u672c\u8eab\u5c31\u662f\u7528\u6765\u590d\u5236YApi\u63d0\u4f9b\u7684API\u8bf7\u6c42\u5730\u5740\uff1b<\/li>\n<li>\u201c\u7f16\u8f91\u201d\u5c31\u662f\u7f16\u8f91\u8bf7\u6c42\u7684\u7c7b\u578b\u3001\u53c2\u6570\u548c\u8fd4\u56de\u7684\u6570\u636e\u7b49\uff0c\u5982\u679c\u6a21\u62df\u7684\u6570\u636e\u504f\u9759\u6001\uff0c\u5219\u8fd9\u4e2a\u9009\u9879\u5361\u662f\u4e3b\u6218\u573a\uff1b<\/li>\n<li>\u201c\u8fd0\u884c\u201d\u8981\u88c5Chrome\u63d2\u4ef6\uff0c\u8fd8\u8981\u7ffbwall\uff0c\u53ef\u4ee5\u5ffd\u7565\uff1b<\/li>\n<li>\u201c\u9ad8\u7ea7mock\u201d\u662f\u7528\u6765\u8bbe\u5b9a\u5220\u9009\u6761\u4ef6\uff0c\u4ee5\u53ca\u81ea\u5df1\u5199JS\u4ee3\u7801\u6839\u636e\u4e0d\u540c\u53c2\u6570\u8fd4\u56de\u4e0d\u540c\u6570\u636e\u7684\uff1b<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_004453.png\" width=\"498\" height=\"373\" alt=\"\u51e0\u4e2a\u9009\u9879\u5361\u4f5c\u7528\u793a\u610f\u8bf4\u660e\" class=\"alignnone\" \/><\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u901a\u8fc7\u51e0\u4e2a\u6848\u4f8b\u7b80\u5355\u4e86\u89e3\u4e0b\u201c\u7f16\u8f91\u201d\u548c\u201c\u9ad8\u7ea7mock\u201d\u3002<\/p>\n<h3>\u4e8c\u3001\u4e86\u89e3\u201c\u7f16\u8f91\u201d\u548c\u201c\u9ad8\u7ea7mock\u201d<\/h3>\n<h4>1. \u65e0\u903b\u8f91\u65e0\u7b5b\u9009\u4e0b\u7684\u201c\u7f16\u8f91\u201d<\/h4>\n<p>\u201c\u7f16\u8f91\u201d\u9002\u5408\u9759\u6001\u7684\u6570\u636e\u6a21\u62df\uff0c\u80fd\u6ee1\u8db3\u5927\u591a\u6570\u7684API\u8bf7\u6c42\u9700\u6c42\u3002<\/p>\n<p>\u201c\u57fa\u672c\u8bbe\u7f6e\u201d\u4e2d\u6211\u4eec\u53ef\u4ee5\u9009\u62e9\u662fGET\u8bf7\u6c42\u8fd8\u662fPOST\u8bf7\u6c42\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_005132.png\" width=\"290\" height=\"177\" alt=\"\u8bf7\u6c42\u7c7b\u578b\u9009\u62e9\" class=\"alignnone\" \/><\/p>\n<p>\u201c\u8bf7\u6c42\u53c2\u6570\u8bbe\u7f6e\u201d\u53ef\u4ee5\u8bbe\u7f6eajax\u8bf7\u6c42\u7684\u67e5\u8be2\u53c2\u6570\uff0c\u4f8b\u5982\uff0c\u6211\u4eec\u5199\u4e00\u4e2a<code>key<\/code>\uff0c\u5e76\u4e14\u662f\u5fc5\u9700\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_005254.png\" width=\"370\" height=\"180\" alt=\"\u5fc5\u9700\u53c2\u6570\" class=\"alignnone\" \/><\/p>\n<p>\u201c\u8fd4\u56de\u6570\u636e\u8bbe\u7f6e\u201d\u8fd9\u4e2a\u5730\u65b9\u6709\u4e2a<code>json-schema<\/code>\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_005412.png\" width=\"289\" height=\"103\" alt=\"json-schema\" class=\"alignnone\" \/><\/p>\n<p>\u5728\u6211\u770b\u6765\uff0c\u5e94\u8be5\u662f\u4f7f\u7528\u53ef\u89c6\u5316\u7684\u65b9\u5f0f\u8bbe\u8ba1\u8bf7\u6c42\u8fd4\u56de\u7684\u6570\u636e\u3002<\/p>\n<p>\u6211\u4e2a\u4eba\u8fd8\u662f\u559c\u6b22\u76f4\u63a5\u770bJSON\u4ee3\u7801\uff0c\u56e0\u6b64\u7f6e\u7070\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_005614.png\" width=\"469\" height=\"345\" alt=\"JSON\u4ee3\u7801\" class=\"alignnone\" \/><\/p>\n<p>\u5176\u4e2d\uff0c\u8fd9\u91cc\u7684JSON\u4ee3\u7801\u5e76\u4e0d\u662f\u7eaf\u9759\u6b62\u7684JSON\u6570\u636e\uff0c\u652f\u6301\u4e00\u4e9b\u7279\u5b9a\u7684\u8bed\u6cd5\u89c4\u5219\uff0c\u53ef\u4ee5\u591a\u6570\u636e\u9009\u4e00\uff0c\u968f\u673a\u6570\u7ec4\u4e2a\u6570\u7b49\u7b49\uff0c\u8fd9\u91cc\u6709\u5f20\u5b98\u65b9\u7684\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/mock-demo.png\" width=\"480\" height=\"276\" alt=\"\u4e00\u4e9b\u7279\u6b8a\u7528\u6cd5\u8bf4\u660e\" class=\"alignnone\" \/><\/p>\n<p>\u5176\u4e2d\u5f88\u591a\u8bed\u6cd5\u89c4\u8303\u6765\u81eaMock.js\uff0c\u5177\u4f53\u53ef<a href=\"https:\/\/github.com\/nuysoft\/Mock\/wiki\/Syntax-Specification\" rel=\"noopener\" target=\"_blank\">\u53c2\u89c1\u8fd9\u91cc<\/a>\u3002<\/p>\n<p>Mock.js \u7684\u8bed\u6cd5\u89c4\u8303\u5305\u62ec\u4e24\u90e8\u5206\uff1a<\/p>\n<ol>\n<li>\u6570\u636e\u6a21\u677f\u5b9a\u4e49\u89c4\u8303\uff08Data Template Definition\uff0cDTD\uff09<\/li>\n<li>\u6570\u636e\u5360\u4f4d\u7b26\u5b9a\u4e49\u89c4\u8303\uff08Data Placeholder Definition\uff0cDPD\uff09<\/li>\n<\/ol>\n<p>\u524d\u8005\u53ef\u4ee5\u5b9e\u73b0\u6570\u503c\u9012\u589e\uff0c\u6570\u503c\u8303\u56f4\uff0c\u81ea\u52a8\u8ba1\u6570\uff0c\u968f\u673a\u6570\u91cf\u751f\u6210\uff0c\u6b63\u5219\u5b57\u7b26\u751f\u6210\u7b49\u3002\u540e\u8005\u5219\u53ef\u4ee5\u7406\u89e3\u5177\u6709\u7279\u5b9a\u8eab\u4efd\u7684\u5360\u4f4d\u7b26\uff0c\u4f8b\u5982<code>@id<\/code>\u4f1a\u751f\u6210\u968f\u673a\u7684<code>id<\/code>\uff0c\u4f60\u53ef\u4ee5\u7406\u89e3\u4e3a\u662f<code>id<\/code>\u7684\u5360\u4f4d\u7b26\uff0c\u5360\u4f4d\u7b26\u5173\u952e\u5b57\u53c8\u5f88\u591a\uff0c\u4f8b\u5982<code>@email<\/code>\u8868\u793a\u90ae\u7bb1\uff0c<code>@name<\/code>\u8868\u793a\u59d3\u540d\u7b49\u3002\u5dee\u4e0d\u591a\u4e0b\u56fe\u51fa\u73b0\u7684\u8fd9\u4e9b\u5355\u8bcd\u90fd\u662f\u5360\u4f4d\u7b26\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_011312.png\" width=\"581\" height=\"572\" alt=\"\u5360\u4f4d\u7b26\u5173\u952e\u5b57\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<p><strong>\u5b9e\u4f8b\u5c55\u793a<\/strong><\/p>\n<p>\u4f8b\u5982\uff0c\u6709\u4e0b\u9762\u7684mock JSON\u6570\u636e\uff1a<\/p>\n<pre>{\n  \"error\": 0,\n  \"data|0-3\": [{\n      \"id\": \"@id\",\n      \"value\": \"@name \"\n    },\n    {\n      \"id\": \"@id\",\n      \"value\": \" @name @word\"\n    },\n    {\n      \"id\": 5,\n      \"value\": \"&lt;img src=\\\"icon_del.png\\\" align=absmiddle&gt;\u652f\u6301\u5c0f\u56fe\u6807\"\n    },\n    {\n      \"id\": 8,\n      \"value\": \"&lt;a href=\\\"?key=\\\"&gt;\u70b9\u51fb\u8df3\u8f6c&lt;\/a&gt;\"\n    }]\n}<\/pre>\n<p>\u8868\u793a<code>\"data\"<\/code>\u540e\u9762\u7684\u6570\u7ec4\u91cc\u9762\u6570\u636e\u968f\u673a\u5faa\u73af0~3\u904d\uff0c\u6ce8\u610f\uff0c\u8fd9\u91cc\u662f\u5faa\u73af0-3\u904d\uff0c\u4e0d\u662f<code>\"data\"<\/code>\u540e\u9762\u7684\u6570\u7ec4\u968f\u673a\u9009\u62e90~3\u9879\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u8fd9\u4e2a\u6a21\u677f\u8fd4\u56de\u7684<code>\"data\"<\/code>\u540e\u9762\u7684\u6570\u7ec4\u6570\u636e\u53ef\u80fd\u662f0\u4e2a\uff0c\u4e5f\u6709\u53ef\u80fd\u662f12\u4e2a\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u67d0\u4e00\u6b21\u8bf7\u6c42\u7684\u8fd4\u56de\u6570\u636e\uff1a<\/p>\n<pre>{\n  \"error\": 0,\n  \"data\": [\n    {\n      \"id\": \"630000199003261731\",\n      \"value\": \"Christopher Hall \"\n    },\n    {\n      \"id\": \"220000201107085094\",\n      \"value\": \" Donald Thomas smse\"\n    },\n    {\n      \"id\": 5,\n      \"value\": \"&lt;img src=\\\"icon_del.png\\\" align=absmiddle&gt;\u652f\u6301\u5c0f\u56fe\u6807\"\n    },\n    {\n      \"id\": 8,\n      \"value\": \"&lt;a href=\\\"?key=\\\"&gt;\u70b9\u51fb\u8df3\u8f6c&lt;\/a&gt;\"\n    }\n  ]\n}<\/pre>\n<p>\u6a21\u677f\u4e2d<code>\"data\"<\/code>\u6570\u7ec4\u5faa\u73af\u4e86\u4e00\u6b21\uff0c\u6570\u7ec4\u4e2d\u524d\u4e24\u9879\u7684<code>id<\/code>\u968f\u673a\u548c<code>value<\/code>\u968f\u673a\uff0c\u56e0\u4e3a\u4f7f\u7528\u4e86<code>@id<\/code>\u5360\u4f4d\u7b26\u548c<code>@name<\/code> <code>@word<\/code>\u5360\u4f4d\u7b26\u3002<\/p>\n<p>\u773c\u89c1\u4e3a\u5b9e\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/l-ui.com\/content\/apis\/datalist.html\" rel=\"noopener\" target=\"_blank\" class=\"a_link\">https:\/\/l-ui.com\/content\/apis\/datalist.html<\/a><\/p>\n<p>\u5176\u4e2d\u201c\u57fa\u4e8eajax\u52a8\u6001\u8fd4\u56de\u6570\u636e\u7684autocomplate\u529f\u80fd\u201d\u7684\u8fd9\u4e2a\u6a21\u62dfAutocomplete\u529f\u80fd\u6240\u53d1\u51fa\u53bb\u7684\u8bf7\u6c42\u5c31\u662f\u7528\u7684\u4e0a\u9762\u7684\u6a21\u677f\uff0c\u6bcf\u8f93\u5165\u4e00\u4e2a\u5185\u5bb9\uff0c\u4e0b\u62c9\u5217\u8868\u7684\u4e2a\u6570\u53ef\u80fd0\u4e2a\uff0c\u53ef\u80fd4\u4e2a\uff0c\u4e5f\u53ef\u80fd8\u4e2a\u2026\u2026<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_012516.png\" width=\"417\" height=\"278\" alt=\"\u4e0b\u62c9\u6a21\u62df\" class=\"alignnone\" \/><\/p>\n<h4>2. \u53ef\u4ee5\u8fd4\u56de\u67e5\u8be2\u6570\u636e\u6216\u8bf7\u6c42\u6570\u636e<\/h4>\n<p>\u6709\u65f6\u5019\u6211\u4eec\u5e0c\u671bAPI\u8fd4\u56de\u7684\u6570\u636e\u5c31\u662f\u6211\u4eec\u63d0\u4ea4\u7684\u6570\u636e\uff0c\u6216\u8005\u5305\u542b\u63d0\u4ea4\u7684\u6570\u636e\uff0cYApi\u4e5f\u662f\u652f\u6301\u7684\u3002<\/p>\n<pre>{\n  <span style=\"color:green;\">\/\/ \u8bf7\u6c42\u7684url\u662f\/path?name=xiaoming, \u8fd4\u56de\u7684name\u5b57\u6bb5\u662fxiaoming<\/span>\n  \"name\": \"${query.name}\", \n  <span style=\"color:green;\">\/\/ \u8bf7\u6c42\u7684requestBody type=1,\u8fd4\u56de\u7684type\u5b57\u6bb5\u662f1<\/span>\n  \"type\": \"${body.type}\"   \n}<\/pre>\n<p>\u5176\u4e2d\uff0c<code>${query.name}<\/code>\u4f60\u53ef\u4ee5\u770b\u6210\u662fGET\u8bf7\u6c42\u7684<code>name<\/code>\u53c2\u6570\u503c\uff0c<code>${body.type}<\/code>\u4f60\u53ef\u4ee5\u770b\u6210\u662fPOST\u8bf7\u6c42\u63d0\u4ea4\u7684<code>type<\/code>\u53c2\u6570\u6570\u636e\u3002<\/p>\n<p><strong>\u5b9e\u4f8b\u5c55\u793a<\/strong><\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u518d\u65b0\u589e\u4e00\u4e2a\u63a5\u53e3\uff0c\u540d\u4e3a\u201clulu\u8868\u5355\u63d0\u4ea4\u201d\uff0c\u9009\u62e9POST\u8bf7\u6c42\uff0c\u540c\u65f6\u8bbe\u7f6e<code>tel<\/code>\u548c<code>code<\/code>\u4e24\u4e2a\u5fc5\u9700\u5b57\u6bb5\uff0c\u8868\u793a\u624b\u673a\u53f7\u548c\u9a8c\u8bc1\u7801\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_013150.png\" width=\"473\" height=\"350\" alt=\"post\u8bf7\u6c42\u53c2\u6570\" class=\"alignnone\" \/><\/p>\n<p>\u540c\u65f6\u6a21\u677f\u6570\u636e\u5982\u4e0b\uff1a<\/p>\n<pre>{\n  \"error|0-1\": 0,\n  \"msg\": \"\u4e00\u5b9a\u6982\u7387\u51fa\u73b0\u7684\u9519\u8bef\",\n  \"data\": {\n    \"tel\": \"${body.tel}\",\n    \"code\": \"${body.code}\"\n  }\n}<\/pre>\n<p>\u5219<code>\"error\"<\/code>\u53c2\u657050%\u6982\u7387\u8fd4\u56de\u503c\u662f1\uff0c\u4e5f\u5c31\u662f\u8ba4\u4e3a\u51fa\u9519\uff1b\u540c\u65f6\uff0c\u539f\u5c01\u4e0d\u52a8\u8fd4\u56de\u63d0\u4ea4\u7684\u7535\u8bdd\u53f7\u7801\u548c\u9a8c\u8bc1\u7801\u3002<\/p>\n<p>\u773c\u89c1\u4e3a\u5b9e\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/l-ui.com\/content\/example\/form.html\" rel=\"noopener\" target=\"_blank\" class=\"a_link\">https:\/\/l-ui.com\/content\/example\/form.html<\/a><\/p>\n<p>\u4e0a\u9762\u7684\u6a21\u677f\u5c31\u662f\u7ed9\u8fd9\u4e2a\u6587\u6863\u9875\u9762\u7684\u8868\u5355\u7528\u7684\uff0c\u70b9\u51fb\u63d0\u4ea4\u6309\u94ae\uff0c50%\u6982\u7387\u51fa\u73b0\u4e0b\u56fe\u6240\u793a\u9519\u8bef\u63d0\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_013729.png\" width=\"450\" height=\"52\" alt=\"\u9519\u8bef\u63d0\u793a\" class=\"alignnone\" \/><\/p>\n<p>50%\u6982\u7387\u5219\u662f\u6210\u529f\u63d0\u793a\uff0c\u5e76\u4e14\u63d0\u793a\u8bed\u4e2d\u5305\u542b\u63d0\u4ea4\u7684\u624b\u673a\u53f7\uff0c\u8fd9\u4e2a\u624b\u673a\u53f7\u5c31\u662fYApi\u8fd4\u56de\u7684\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_013846.png\" width=\"414\" height=\"221\" alt=\"\u6210\u529f\u63d0\u793a\u8f93\u5165\u6846\" class=\"alignnone\" \/><\/p>\n<h4>3. \u5177\u6709\u7b5b\u9009\u529f\u80fd\u751a\u81f3\u590d\u6742\u903b\u8f91\u7684\u201c\u9ad8\u7ea7mock\u201d<\/h4>\n<p>\u201c\u9ad8\u7ea7mock\u201d\u6709\u4e24\u4e2a\u9009\u9879\u5361\uff0c\u4e00\u4e2a\u662f\u201c\u671f\u671b\u201d\uff0c\u4e00\u4e2a\u662f\u201c\u811a\u672c\u201d\u3002<\/p>\n<p>\u5176\u4e2d\uff0c\u201c\u671f\u671b\u201d\u610f\u601d\u662f\uff0c\u5f53\u4f60\u8f93\u8bf7\u6c42\u53c2\u6570\u662f\u8fd9\u4e2a\u7684\u65f6\u5019\uff0c\u6211\u7ed9\u4f60\u8fd4\u56de\u4e00\u4e2a\u7279\u6b8a\u7684\u6570\u636e\u3002\u4f8b\u5982\uff0c\u624b\u673a\u53f711234567890\u662f\u7ba1\u7406\u5458\u8d26\u53f7\uff0c\u7ba1\u7406\u5458\u8fd4\u56de\u6570\u636e\u8981\u548c\u666e\u901a\u6210\u5458\u4e0d\u4e00\u6837\uff0c\u8fd9\u65f6\u5019\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528\u671f\u671b\u6765\u5904\u7406\u3002<br \/>\n\u201c\u811a\u672c\u201d\u5219\u662f\u53ef\u4ee5\u81ea\u5df1\u5199JavaScript\u903b\u8f91\uff0c\u81ea\u5df1\u521b\u9020\u6570\u636e\uff0c\u60f3\u8fd4\u56de\u4ec0\u4e48\u5c31\u662f\u4ec0\u4e48\uff0c\u53ef\u4ee5\u8bf4\u662f\u6570\u636e\u4f2a\u9020\u7684\u7ec8\u6781\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p><strong>\u5b9e\u4f8b\u5c55\u793a<\/strong><\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u518d\u65b0\u589e\u4e00\u4e2a\u63a5\u53e3\uff0c\u540d\u4e3a\u201clulu\u5bcc\u4ea4\u4e92\u5217\u8868\u201d\uff0c\u9009\u62e9GET\u8bf7\u6c42\uff0c\u76f4\u63a5\u8fdb\u884c\u201c\u9ad8\u7ea7mock\u201d\u5904\u7406\u3002<\/p>\n<p>\u8fd9\u4e2a\u5b9e\u4f8b\u8981\u5148\u770b\u9875\u9762\uff0c\u5177\u6709\u590d\u6742\u903b\u8f91\uff0c\u771f\u5206\u9875lulu\u5bcc\u4ea4\u4e92\u5217\u8868\uff1a<a href=\"https:\/\/l-ui.com\/content\/example\/table.html\" rel=\"noopener\" target=\"_blank\" class=\"a_link\">https:\/\/l-ui.com\/content\/example\/table.html<\/a><\/p>\n<p>\u8fd9\u4e2a\u9875\u9762\u70b9\u51fb\u5206\u9875\u6570\u636e\u90fd\u662f\u771f\u7684\u5206\u9875\uff0c\u641c\u7d22\uff0c\u6279\u91cf\u5220\u9664\u90fd\u6709\u529f\u80fd\uff0c\u751a\u81f3\u8fd8\u6709\u5f69\u86cb\uff0c\u5168\u90e8\u90fd\u662f\u201c\u9ad8\u7ea7mock\u201d\u641e\u5b9a\u7684\uff0c\u201c\u671f\u671b\u201d\u548c\u201c\u811a\u672c\u201d\u90fd\u4f7f\u7528\u4e86\uff0c\u6211\u4eec\u4e00\u4e2a\u4e00\u4e2a\u770b\u4e0b\u3002<\/p>\n<p>\u9996\u5148\uff0c\u8f93\u5165\u6846\u641c\u7d22<code>error<\/code>\u4f1a\u6f14\u793a\u51fa\u9519\u6548\u679c\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_014900.png\" width=\"826\" height=\"342\" alt=\"\u6570\u636e\u51fa\u9519\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<p>\u76f8\u5173\u7684\u201c\u671f\u671b\u201d\u8bbe\u7f6e\u5982\u4e0b\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_015243.png\" width=\"645\" height=\"431\" class=\"alignnone\" \/><\/p>\n<p>\u7136\u540e\uff0c\u56de\u5230\u521d\u59cb\u6001\uff0c\u6211\u4eec\u9009\u62e9\u4efb\u610f\u5217\u8868\uff0c\u7136\u540e\u6279\u91cf\u5220\u9664\uff0c\u5219\u5217\u8868\u4f1a\u4e3a\u7a7a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_015437.png\" width=\"466\" height=\"242\" alt=\"\u5220\u9664\u4e3a\u7a7a\" class=\"alignnone\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_015520.png\" width=\"675\" height=\"424\" alt=\"\u6570\u636e\u4e3a\u7a7a\u7684\u5217\u8868\" class=\"alignnone\" \/><\/p>\n<p>\u76f8\u5173\u7684\u201c\u671f\u671b\u201d\u8bbe\u7f6e\u5982\u4e0b\uff0c\u8bbe\u7f6e\u671f\u671b\u6761\u4ef6\uff0c\u5f53<code>action<\/code>\u4e3a<code>'delete'<\/code>\uff0c\u8fd4\u56de\u7a7a\u6570\u636e\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_015735.png\" width=\"495\" height=\"433\" alt=\"\u53c2\u6570\u8fc7\u6ee4\u6570\u636e\u4e3a\u7a7a\" class=\"alignnone\" \/><\/p>\n<p>\u6700\u540e\uff0c\u770b\u770b\u4e00\u5f00\u59cb\u7684\u771f\u5206\u9875\uff0c\u548c\u641c\u7d22\u968f\u673a\u5217\u8868\u6570\u91cf\u6548\u679c\u662f\u600e\u6837\u5904\u7406\u7684\uff0c\u5c31\u50cf\u5e73\u5e38\u5199JavaScript\u8bed\u8a00\u4e00\u6837\uff0c\u5728\u201c\u811a\u672c\u201d\u8fd9\u4e2a\u8f93\u5165\u6846\u4e2d\u5199\u6211\u4eec\u7684\u903b\u8f91\u5373\u53ef\uff0c\u53ea\u8981\u4fdd\u8bc1\u6700\u540emockJSON\u6570\u636e\u662f\u6211\u4eec\u5e0c\u671b\u8fd4\u56de\u7684\u6570\u636e\u5373\u53ef\uff01<\/p>\n<p>\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>var data = [{\n    \"id\": 1,\n    \"title\": \"\u6d45\u8bae\u661f\u661f\u7684\u82b1\u6735\",\n    \"time\": \"2015-07-20 16:23\",\n    \"comment\": 7,\n    \"deleted\": false\n}, <span style=\"color:green;\">\/* ... \u8fd9\u91cc\u7701\u7565\u4e2d\u95f4\u768447\u9879 ... *\/<\/span> {\n    \"id\": 48,\n    \"title\": \"\u4ea7\u54c1\u7ec6\u8282\u4e2d\u7684\u60c5\u611f\u5316\u8bbe\u8ba1\",\n    \"time\": \"2015-06-01 21:14\",\n    \"comment\": 0,\n    \"deleted\": false\n}];\n\nvar current = params.current;\nvar every = params.every;\n\nvar begin = 0;\nvar end = 0;\n\nvar total = data.length;\n\nif (!params.key) {\n    <span style=\"color:green;\">\/\/ \u6b63\u5e38\u5206\u9875<\/span>\n    begin = (current - 1) * every;\n    end = every;\n} else {\n    begin = Math.round(25 * Math.random());\n    end = Math.round(20 * Math.random());\n    \n    total = end;\n}\n\nvar dataGet = data.slice(begin, begin + end);\n   \nmockJson = {\n    error: 0,\n    data: {\n        total: total,\n        data: dataGet\n    }\n}\n<\/pre>\n<p>\u622a\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-09_022515.png\" width=\"778\" height=\"688\" alt=\"\u811a\u672c\u4ee3\u7801\u622a\u56fe\" class=\"alignnone\" \/><\/p>\n<p>\u4e5f\u5c31\u662f\u9ed8\u8ba4\u5199\u6b7b\u5dee\u4e0d\u591a50\u6761\u5217\u8868\u6570\u636e\uff08\u53ef\u4ee5\u901a\u8fc7\u201c\u7f16\u8f91\u6a21\u677f\u201d\u548c\u5360\u4f4d\u7b26\u8fc5\u901f\u751f\u6210\uff09\uff0c\u7136\u540e\u6839\u636e\u8bf7\u6c42\u7684\u53c2\u6570\u8fdb\u884c\u903b\u8f91\u5904\u7406\u3002<\/p>\n<p>\u5176\u4e2d<code>params.xxxx<\/code>\u53ef\u4ee5\u83b7\u5f97\u65e0\u8bba\u662fPOST\u8fd8\u662fGET\u8bf7\u6c42\u53d1\u9001\u7684<code>xxxx<\/code>\u53c2\u6570\u7684\u503c\uff0c\u4e8e\u662f\uff0c\u6211\u4eec\u53ef\u4ee5\u548c\u4ece\u5bb9\u5730\u4e66\u5199\u903b\u8f91\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u672c\u4f8b\u5b50\u4e2d\uff0c\u5982\u679c\u6709<code>params.key<\/code>\u8fd9\u4e2a\u53c2\u6570\u503c\uff0c\u8ba4\u4e3a\u662f\u641c\u7d22\uff0c\u5219\u8fd4\u56de\u968f\u673a\u4e2a\u6570\u7684\u5217\u8868\uff1b\u5982\u679c\u6ca1\u6709<code>params.key<\/code>\uff0c\u5219\u8ba4\u4e3a\u662f\u521d\u59cb\u8f7d\u5165\uff0c\u5219\u6839\u636e\u5f53\u524d\u7684\u5206\u9875\u9875\u9762\uff0c\u548c\u7528\u6237\u9009\u62e9\u7684\u6bcf\u9875\u5217\u8868\u6761\u6570\u51c6\u786e\u8fd4\u56de\u5217\u8868\u6570\u76ee\uff0c\u4e8e\u662f\u4e00\u4e2a\u9ad8\u4fdd\u771f\u7684\u5bcc\u4ea4\u4e92\u5217\u8868\u6548\u679c\u5c31\u51fa\u6765\u4e86\uff0c\u5404\u79cd\u4f53\u9a8c\u548c\u4ea4\u4e92\u95ee\u9898\u5c31\u80fd\u5f88\u597d\u5730\u6d4b\u8bd5\u4e86\u3002<\/p>\n<h4>4. \u4e09\u8005\u7684\u4f18\u5148\u7ea7\u5173\u7cfb<\/h4>\n<p>\u8bf7\u6c42\u6211\u4eec\u6a21\u62df\u6570\u636e\u65f6\uff0c\u89c4\u5219\u5339\u914d\u4f18\u5148\u7ea7\uff1a\u671f\u671b > \u81ea\u5b9a\u4e49\u811a\u672c > \u666e\u901a\u6a21\u677f\u3002<\/p>\n<p>\u5982\u679c\u524d\u9762\u5339\u914d\u5230\u6570\u636e\uff0c\u540e\u9762\u7684\u5219\u4e0d\u8fd4\u56de\u6570\u636e\u3002<\/p>\n<h3>\u4e09\u3001YApi\u7684\u5c40\u9650<\/h3>\n<p>\u4e0d\u652f\u6301https\u8bf7\u6c42\uff0c\u5982\u679c\u5927\u5bb6\u539f\u578b\u9875\u9762\u662fhttps\u534f\u8bae\u7684\uff0c\u5219YApi\u4e0d\u80fd\u76f4\u63a5\u4f7f\u7528\uff0c\u53ef\u4ee5\u641e\u4e2ahttps\u9875\u9762\u53cd\u5411\u4ee3\u7406\u4e0b\u3002\u6216\u8005\u4f7f\u7528EasyApi\uff0c\u6309\u7167\u540c\u65f6\u8bf4\u6cd5\uff0c\u8fd9\u4e2a\u662f\u652f\u6301https\uff0c\u4e0d\u8fc7\u6211\u4e2a\u4eba\u5e76\u6ca1\u6709\u6d4b\u8bd5\u3002<\/p>\n<h3>\u56db\u3001\u7ed3\u675f\u8bed<\/h3>\n<p>\u672c\u6587\u6d0b\u6d0b\u6d12\u6d12\u8fd9\u4e48\u957f\uff0c\u4e3b\u8981\u5c55\u793a\u4e2a\u4f53\u5728\u5f00\u53d1\u9ad8\u4fdd\u771fHTML\u9875\u9762\u65f6\u5019\uff0c\u5982\u4f55\u501f\u52a9API\u63a5\u53e3\u5e73\u53f0\u5de5\u5177\uff0c\u8ba9\u6211\u4eec\u7684\u9875\u9762\u7684\u4ea4\u4e92\u4f53\u9a8c\u505a\u5230\u5c3d\u5584\u5c3d\u7f8e\uff0c\u66f4\u5065\u58ee\uff0c\u8ba9\u8bbe\u8ba1\u5e08\u548c\u5f00\u53d1\u4eba\u89c1\u4eba\u7231\u3002<\/p>\n<p>\u4f46\u4e2a\u4f53\u6d89\u53ca\u7684\u77e5\u8bc6\u70b9\u53ea\u662fYApi\u4e2d\u8f83\u5c0f\u7684\u4e00\u90e8\u5206\uff0c\u66f4\u591a\u5185\u5bb9\uff0c\u5c24\u5176\u56e2\u961f\u5185\u7f51\u90e8\u7f72\u7b49\u8fd8\u9700\u8981\u591a\u591a\u53c2\u8003API\u6587\u6863\uff1a<a href=\"https:\/\/yapi.ymfe.org\/index.html\" rel=\"noopener\" target=\"_blank\">https:\/\/yapi.ymfe.org\/index.html<\/a><\/p>\n<p>\u4e00\u70b9\u5c0f\u5206\u4eab\uff0c\u81ea\u5df1\u5907\u5fd8\u540c\u65f6\u5e0c\u671b\u53ef\u4ee5\u5e2e\u5230\u5bf9API\u5e73\u53f0\u6709\u5174\u8da3\u7684\u5c0f\u4f19\u4f34\u3002<\/p>\n<p>\u6700\u540e\uff0c\u611f\u8c22\u53bb\u54ea\u513f\u7f51<a href=\"https:\/\/ymfe.org\/\" rel=\"noopener\" target=\"_blank\">\u79fb\u52a8\u5927\u524d\u7aef\u6280\u672f\u4e2d\u5fc3<\/a>\u5bf9\u672c\u5de5\u5177\u7684\u5f00\u6e90\u8d21\u732e\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201611\/14.png\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u4f1a\u7ecf\u5e38\u66f4\u65b0\u77e5\u8bc6\u70b9\u4ee5\u53ca\u4fee\u6b63\u4e00\u4e9b\u9519\u8bef\uff0c\u56e0\u6b64\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u539f\u51fa\u5904\uff0c\u65b9\u4fbf\u6eaf\u6e90\uff0c\u907f\u514d\u9648\u65e7\u9519\u8bef\u77e5\u8bc6\u7684\u8bef\u5bfc\uff0c\u540c\u65f6\u6709\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=7564\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=7564<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u540c\u4e8b\u7684\u5b89\u5229\u4e0b\uff0c\u8bd5\u7528\u4e86\u4e0b\u63a5\u53e3\u7ba1\u7406\u5e73\u53f0YApi\uff0c\u7528\u4e86\u4e0b\uff0c\u8fd8\u884c\u3002\u81ea\u5df1\u5199\u9ad8\u4fdd\u771f\u7684\u4ea4\u4e92\u539f\u578b\uff0c\u9700\u8981\u53ef\u4ee5\u6709\u76f8\u5f53\u771f\u5b9e\u7684API\u8bf7\u6c42\u6570\u636e\uff0c\u4f8b\u5982\u51fa\u9519\uff0c\u8bf7\u6c42\u5ef6\u65f6\u6a21\u62df\uff0c\u6781\u7aef\u6570\u636e\u5904\u7406\u7b49\u3002YApi\u6b63\u597d\u53ef\u4ee5\u6ee1\u8db3\u8fd9\u65b9\u9762\u7684\u9700\u6c42\uff0c\u7279\u8bb0\u5f55\u4e0e\u5206\u4eab\u4e0b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[180],"tags":[215,356,1248,1249,1247,881],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/7564"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=7564"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/7564\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=7564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=7564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=7564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}