{"id":325636,"date":"2021-02-07T16:05:09","date_gmt":"2021-02-07T08:05:09","guid":{"rendered":"http:\/\/4563.org\/?p=325636"},"modified":"2021-02-07T16:05:09","modified_gmt":"2021-02-07T08:05:09","slug":"%e5%bc%80%e6%ba%90-800-bytes-%e7%94%a8%e4%b8%80%e4%b8%aa%e6%9b%b4%e7%88%bd%e7%9a%84%e6%96%b9%e5%bc%8f%e7%94%9f%e6%88%90-mock-%e5%81%87%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=325636","title":{"rendered":"[\u5f00\u6e90] &lt; 800 bytes \u7528\u4e00\u4e2a\u66f4\u723d\u7684\u65b9\u5f0f\u751f\u6210 mock \u5047\u6570\u636e"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  [\u5f00\u6e90] &lt; 800 bytes \u7528\u4e00\u4e2a\u66f4\u723d\u7684\u65b9\u5f0f\u751f\u6210 mock \u5047\u6570\u636e               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : 50vip <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6700\u8fd1\u5728\u505a\u53ef\u89c6\u5316\u56fe\u8868 G2Plot \u7684\u6027\u80fd\u6d4b\u8bd5\u548c\u4f18\u5316\uff0c\u7b2c\u4e00\u6b65\u5c31\u662f mock \u6307\u5b9a\u7ed3\u6784\u7684\u6570\u636e\uff0c\u4e00\u822c\u5927\u5bb6\u90fd\u7528 mockjs\uff0c\u4f46\u662f\u6211\u770b\u4e86 API \u548c\u8bed\u6cd5\uff0c\u611f\u89c9\u6709\u70b9\u9ed1\u4e86\uff0c\u4e0d\u597d\u7528\uff0c\u4e8e\u662f\u81ea\u5df1\u9020\u4e86\u4e00\u4e2a\u8f6e\u5b50\uff08 miz \uff09\uff0c\u611f\u89c9\u4ee3\u7801\u5199\u7684\u8fd8\u4e0d\u9519\uff0c\u5206\u4eab\u7ed9\u5927\u5bb6\uff01<\/p>\n<h2>\u9879\u76ee\u5730\u5740\uff1amiz<\/h2>\n<p>\u4e3e\u4f8b\u5b50\uff0c\u751f\u6210\u4e00\u4e2a\u957f\u5ea6\u4e3a 2 \u7684\u7528\u6237\u4fe1\u606f\u3002\uff08\u4f7f\u7528\u65b9\u6cd5\u7c7b\u4f3c\u4e8e react \u7684 prop-types \uff09<\/p>\n<pre><code>import { M } from 'miz';  const m = M.arrayOf(M.shape({   id: M.number(10000, 1000000),     \/\/ id is between 10000 ~ 1000000.   name: M.string(6),                \/\/ 6 length random string.   sex: M.bool(),                    \/\/ random true or false.   city: 'hz',                        \/\/ constant value.   work: M.oneOf(['QA', 'FED'])      \/\/ random from array }), 2);                              \/\/ list length is 2.  m.mock();  <\/code><\/pre>\n<p>Then will get the mock variable like below:<\/p>\n<pre><code>[{  id: 757852,  name: 'mU7RTB',  sex: false,  city: 'hz',  work: 'FED' }, {  id: 359987,  name: 'jWuKxX',  sex: true,  city: 'hz',  work: 'FED' }] <\/code><\/pre>\n<p>\u5982\u679c\u89c9\u5f97\u597d\u7528\uff0c\u4e0d\u541d\u70b9\u4e2a star ^_^<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>13<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5213887\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5047\u6570\u636e\u4e0d\u662f mock \u800c\u662f dummy data \u6216\u8005 fake data \u3002mock \u662f\u6307\u5047\u8c03\u7528<br \/>\u641c\u7d22\u4e86\u4e00\u4e0b\uff0c\u6bd4\u5982 npm i fake-data-generator \u8fd9\u4e2a\uff0c\u5176\u5b9e\u5f88\u50cf\uff0c\u4e0d\u8fc7\u662f\u5199 json \u914d\u7f6e\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5213888\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u770b\u4e86\u4e00\u4e0b\uff0c\u5176\u5b9e\u4f60\u8fde mockjs \u7684 Get Started \u793a\u4f8b\u90fd\u4e0d\u80fd\u7528\u6b63\u5e38\u65b9\u6cd5\u505a\u51fa\u6765\u5427<br \/>\u600e\u4e48\u505a\u4e00\u4e2a\u81ea\u589e\u952e\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5213889\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : 50vip <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @no1xsyzy miz \u4e3b\u8981\u6700\u968f\u673a\u3002\u5bf9\u4e8e\u5e8f\u5217\u662f\uff1a<\/p>\n<p>M.apply(() =&gt; {});                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5213890\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : THP301 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             mock \u5f62\u5bb9\u8bcd: \u865a\u5047, \u865a\u8bbe, \u4e49<br \/>mock \u5047\u6570\u636e = \u865a\u5047\u7684\u5047\u6570\u636e = \u771f\u6570\u636e \uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5213891\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @50vip \u6211\u662f\u8bf4 [{id:1}, {id:2}, {id:3}] \u8fd9\u79cd\uff0c\u4f60\u5fc5\u987b\u5728\u5916\u9762\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cf\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5213892\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : 50vip <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @no1xsyzy M.apply(() =&gt; _.uniqueId());                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5213893\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : 50vip <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @no1xsyzy \u5c31\u662f\u4e0d\u60f3\u7528 mockjs \u7684\u90a3\u4e2a\u4e0d\u662f\u5f88\u61c2\u7684\u8bed\u6cd5\uff0c\u6240\u4ee5\u64b8\u4e86\u4e00\u4e2a\u8f6e\u5b50\u3002~~                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5213894\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : YouLMAO <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5927\u90e8\u5206\u7684\u6d4b\u8bd5\u90fd\u662f\u786e\u5b9a\u6027\u7684\uff0c\u4e0d\u662f\u968f\u673a\u6570\u636e\u4e5f\u4e0d\u662f\u81ea\u589e\u6570\u636e                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5213895\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : YouLMAO <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8981\u5148\u6709\u9700\u6c42\u518d\u505a\u4ea7\u54c1                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5213896\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @YouLMAO \u81ea\u589e\u662f\u786e\u5b9a\u6027\u7684\u3002<br \/>\u4e00\u822c\u53ea\u8dd1\u4e00\u6b21\u4e4b\u540e\u5c31\u7528\u540c\u4e00\u4e2a\u6570\u636e\u96c6\u4e86\u3002\u4f60\u603b\u4e0d\u89c1\u5f97\u62ff\u7ebf\u4e0a\u6570\u636e\u6d4b\u8bd5\uff0c\u6216\u8005\u624b\u64b8\u5047\u6570\u636e\u3002<\/p>\n<p>@50vip \u6240\u4ee5\u8bf4\u8fd8\u662f\u5916\u90e8\u53d8\u91cf\uff0c\u800c\u4e14\u8d77\u59cb\u70b9\u8fd8\u4e0d\u53d7\u63a7<br \/>\u597d\uff0c\u90a3\u4e48\u6765\u4e2a\u8fd9\u4e2a\uff1a\u4e00\u4e2a\u5217\u8868\uff0c\u6bcf\u4e2a\u5143\u7d20\u662f\u7ae0\u8282\u5e8f\u53f7\u548c\u5c5e\u4e8e\u8be5\u7ae0\u8282\u7684\u56fe\u7247\u5217\u8868\u3001\u4ee3\u7801\u5757\u5217\u8868<br \/>\u6bcf\u4e2a\u56fe\u7247\u5217\u8868\u7684 ref \u5e94\u5f53\u662f \u201c\u56fe &lt;\u7ae0\u8282\u5e8f\u53f7&gt;-&lt;\u8be5\u7ae0\u8282\u5185\u7684\u56fe\u7247\u5e8f\u53f7&gt;\u201d\uff0c\u4ee3\u7801\u5757\u5217\u8868\u7c7b\u4f3c\u3002<br \/>\u7528\u4f60\u7684\u5e93\u5199\u5199\u770b\uff1f<br \/>\u4f60\u5e95\u5c42\u62bd\u8c61\u5f7b\u5e95\u9519\u4e86\u3002\u64cd\u4f5c\u6570\u636e\u5e94\u5f53\u4f7f\u7528\u51fd\u6570\u5f0f\u8303\u5f0f\u3002<br \/>https:\/\/gist.github.com\/no1xsyzy\/3cc83e5da3fca783deb74954b915baa0 <button onclick=\"lazyGist(this)\">\u00a0\u663e\u793a Gist \u4ee3\u7801\u00a0<\/button> <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5213897\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : YouLMAO <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @no1xsyzy \u5efa\u8bae\u4f60\u770b\u770b gmock \u6846\u67b6, <\/p>\n<p>\u81ea\u589e\u662f\u786e\u5b9a\u6027\u7684, \u4f46\u5f88\u5c11\u573a\u666f\u4f1a\u7528\u5230, \u4e3e\u4e2a\u4f8b\u5b50 \u4ee3\u7801\u9762\u8bd5\u8981\u4f60\u6d4b\u81ea\u5df1\u7a0b\u5e8f testcase \u4f60\u8f93\u5165 1,2,3,4 \u5417, \u80af\u5b9a\u662f-1,0,1,+IntMax \u7b49\u8fb9\u754c\u6761\u4ef6\u54af, \u6d4b\u4e86 2,\u5c31\u4e0d\u9700\u8981\u6d4b 3 \u548c 4 \u4e86                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5213898\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53e6\u5916\uff0carrayOf \u6709\u4e2a bug\uff0c\u4f60\u6ca1\u6cd5\u8c03\u6700\u77ed\u4e3a 0 \u7684 array \u3002<br \/>M.arrayOf(&#8230;, 0, 5) \u4f1a\u4ea7\u751f\u4e00\u4e2a\u6700\u77ed\u4e3a 5 \u6700\u957f\u4e3a 20 \u7684\u5e8f\u5217\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5213899\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @YouLMAO \u54e6\u5ffd\u7565\u4e86\u8fd9\u70b9\uff0c\u5355\u5143\u6d4b\u8bd5\u4e0d\u5e38\u7528\u2026\u2026<br \/>\u6027\u80fd\u6d4b\u8bd5\u548c\u9ed1\u7bb1\u6d4b\u8bd5\uff08\u4eba\u5de5\uff09\u7684\u8bdd\uff0c\u7528 dummy \u6570\u636e\u7684\u4f1a\u6bd4\u8f83\u591a\u3002<\/p>\n<p>gmock \u4f3c\u4e4e\u662f mock \u800c\u4e0d\u662f\u5047\u6570\u636e\u751f\u6210\u5668\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>[\u5f00\u6e90] &lt; 800 byt&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/325636"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=325636"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/325636\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=325636"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=325636"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=325636"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}