<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] >[success] # Mock簡明文檔 下面是一個 **mock** 的一個精簡的一個小文檔可以便于查看 >[success] ## Mock.mock() - Mock.mock( requestUrl?, requestType?, template|function(options) ) - Mock.mock( template ) - Mock.mock( requestUrl, template ) - Mock.mock( requestUrl, requestType, template ) - Mock.mock( requestUrl, requestType, function(options) ) > requestUrl: 要攔截的URL,字符串或正則表達式<br> equestType: 要攔截的請求類型,get/post/put/delete/options...<br> template: 數據模板<br> function(options):生成響應數據的函數,options --> { url, type, body } ---- >[success] ## 語法規范 >[success] ### 數據模板定義 > 數據模板中每個屬性由3部分組成: **屬性名|生成規則:屬性值** 1. 'name|min-max': value 2. 'name|count': value 3. 'name|min-max.dmin-dmax': value 4. 'name|min-max.dcount': value 5. 'name|count.dmin-dmax': value 6. 'name|count.dcout': value 7. 'name|+step': value *屬性值*中可以包含@占位符 *屬性值*還指定了最終值的初始值和類型 >[success] #### 1.屬性值是字符串 1. 'name|min-max': string > 通過重復 string 生成一個字符串,重復次數大于等于 min,小于等于 max 2. 'name|count': string > 通過重復 string 生成一個字符串,重復次數等于 count >[success] #### 2.屬性值是數字 1. 'name|+1': number > 屬性值自動加 1,初始值為 number 2. 'name|min-max': number > 生成一個大于等于 min、小于等于 max 的整數,屬性值 number 只是用來確定類型 3. 'name|min-max.dmin-dmax': number > 生成一個浮點數,整數部分大于等于 min、小于等于 max,小數部分保留 dmin 到 dmax 位 >[success] #### 3.屬性值是布爾值 1. 'name|1': boolean > 隨機生成一個布爾值,值為 true 的概率是 1/2,值為 false 的概率同樣是 1/2 2. 'name|min-max': value > 隨機生成一個布爾值,值為 value 的概率是 min / (min + max),值為 !value 的概率是 max / (min + max) >[success] #### 4.屬性值是對象 1. 'name|count': object > 從屬性值 object 中隨機選取 count 個屬性 2. 'name|min-max': object > 從屬性值 object 中隨機選取 min 到 max 個屬性 >[success] #### 5.屬性值是數組 1. 'name|1': array > 從屬性值 array 中隨機選取 1 個元素,作為最終值 2. 'name|+1': array > 從屬性值 array 中順序選取 1 個元素,作為最終值 3. 'name|min-max': array > 通過重復屬性值 array 生成一個新數組,重復次數大于等于 min,小于等于 max 4. 'name|count': array > 通過重復屬性值 array 生成一個新數組,重復次數為 count >[success] #### 6.屬性值是函數 1. 'name': function > 執行函數 function,取其返回值作為最終的屬性值,函數的上下文為屬性 'name' 所在的對象 >[success] #### 7.屬性值是正則表達式 1. 'name': regexp > 根據正則表達式 regexp 反向生成可以匹配它的字符串。用于生成自定義格式的字符串 >[success] ### 數據占位符定義 1. 用 @ 來標識其后的字符串是 占位符 2. 占位符 引用的是 Mock.Random 中的方法 3. 通過 Mock.Random.extend() 來擴展自定義占位符 4. 占位符 也可以引用 數據模板 中的屬性 5. 占位符 會優先引用 數據模板 中的屬性 6. 占位符 支持 相對路徑 和 絕對路徑 ---- >[success] ## Mock.setup() > 配置Ajax請求的行為,暫時支持的配置項有timeout ```javascript Mock.setup({ timeout: 500 }) Mock.setup({ timeout: '100-600' }) ``` ---- >[success] ## Mock.Random ```javascript const Random = Mock.Random Random.email() // => sd.sdf@oksd.com Mock.mock('@email') // => sd.sdf@oksd.com Mock.mock({ email: 'sd.sdf@oksd.com' }) // => { email: "sd.sdf@oksd.com" } ``` >[success] ### Mock.Random提供的完整方法(占位符): Type | Method :------- | :------- Basic | boolean, natural, integer, float, character, string, range, date, time, datetime, now Image | image, dataImage Color | color Text | paragraph, sentence, word, title, cparagraph, csentence, cword, ctitle Name | first, last, name, cfirst, clast, cname Web | url, domain, email, ip, tld Address | area(region, province, city(bool), county(bool), zip), region Helper | capitalize(首字母大寫), upper(大寫), lower(小寫), pick(從數組任取一個), shuffle(打亂數組元素順序) Miscellaneous | guid, id >[success] #### Basic 1. Random.boolean(min?, max?, current? ) 2. Random.natural(min?, max? ) 3. Random.integer(min?, max? ) 4. Random.float( min?, max?, dmin?, dmax? ) 5. Random.character( pool? ) // pool => lower/upper/number/symbol 6. Random.string( pool?, min?, max? ) // pool => lower/upper/number/symbol 7. Random.range( start?, stop, step? ) >[success] #### Date 1. Random.date( format? ) Format | Description | Example :---- | :---- | :---- yyyy | A full numeric representation of a year, 4 digits | 1999 or 2003 yy | A two digit representation of a year | 99 or 03 y | A two digit representation of a year | 99 or 03 MM | Numeric representation of a month, with leading zeros | 01 to 12 M | Numeric representation of a month, without leading zeros | 1 to 12 dd | Day of the month, 2 digits with leading zeros | 01 to 31 d | Day of the month without leading zeros | 1 to 31 HH | 24-hour format of an hour with leading zeros | 00 to 23 H | 24-hour format of an hour without leading zeros | 0 to 23 hh | 12-hour format of an hour without leading zeros | 01 to 12 h | 12-hour format of an hour with leading zeros | 1 to 12 mm | Minutes, with leading zeros | 00 to 59 m | Minutes, without leading zeros | 0 to 59 ss | Seconds, with leading zeros | 00 to 59 s | Seconds, without leading zeros | 0 to 59 SS | Milliseconds, with leading zeros | 000 to 999 S | Milliseconds, without leading zeros | 0 to 999 A | Uppercase Ante meridiem and Post meridiem | AM or PM a | Lowercase Ante meridiem and Post meridiem | am or pm T | Milliseconds, since 1970-1-1 00:00:00 UTC | 759883437303 2. Random.time( format? ) 3. Random.datetime( format? ) 4. Random.now( unit?, format? ) // unit => year、month、week、day、hour、minute、second、week >[success] #### Image >[success] ##### Random.image() 1. Random.image() 2. Random.image( size ) 3. Random.image( size, background ) 4. Random.image( size, background, text ) 5. Random.image( size, background, foreground, text ) 6. Random.image( size, background, foreground, format, text ) >[success] ##### Random.dataImage() 1. Random.dataImage() 2. Random.dataImage( size ) 3. Random.dataImage( size, text ) >[success] #### Color 1. Random.color() // => #3538B2 2. Random.hex() // => #3538B2 3. Random.rgb() // => rgb(242, 198, 121) 4. Random.rgba() // => rgba(242, 198, 121, 0.13) 5. Random.hsl() // => hsl(345, 82, 71) >[success] #### Text 1. Random.paragraph( min?, max? ) 2. Random.cparagraph( min?, max? ) 3. Random.sentence( min?, max? ) 4. Random.csentence( min?, max? ) 5. Random.word( min?, max? ) 6. Random.cword( pool?, min?, max? ) 7. Random.title( min?, max? ) 8. Random.ctitle( min?, max? ) >[success] #### Name 1. Random.first() 2. Random.last() 3. Random.name( middle? ) 4. Random.cfirst() 5. Random.clast() 6. Random.cname() >[success] #### Web 1. Random.url( protocol?, host? ) 2. Random.protocol() 3. Random.domain() // 域名 4. Random.tld() // 頂級域名 5. Random.email( domain? ) 6. Random.ip() >[success] #### Address 1. Random.region() 2. Random.province() 3. Random.city( prefix? ) 4. Random.county( prefix? ) 5. Random.zip() >[success] #### Helper 1. Random.capitalize( word ) 2. Random.upper( str ) 3. Random.lower( str ) 4. Random.pick( arr ) 5. Random.shuffle( arr ) >[success] #### Miscellaneous 1. Random.guid() 2. Random.id() 3. Random.increment( step? ) ---- >[success] ### 擴展 ```javascript Random.extend({ fruit () { const fruit = ['apple', 'peach', 'lemon'] return this.pick(fruit) } }) Random.fruit() // => 'peach' Mock.mock('@fruit') // => 'lemon' Mock.mock({ fruit: '@fruit' // => 'peach' }) ``` >[success] ### Mock.valid() >[success] #### Mock.valid( template, data ) >[success] ### Mock.toJSONSchema() >[success] #### Mock.toJSONSchema( template )
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看