WeChat applet combined with mock.js implementation background simulation and debugging

First, create a small program project

微信小程序结合mock.js实现后台模拟及调试

Mock.js download from https://github.com/nuysoft/mock/blob/refactoring/dist/mock.js

API.JS: Configure analog data and background interface data, through debug = true; // Switch data entry

 Let API_HOST = "http: / / xxx.com/xxx";let debug = true; // Switch data entry var mock = required ('mock.js') function ajax (data =', fn, method = "get", header = {}) {if (! debug) {wx.Request ({url: config.api_host + data, method: method: {}: {"content-type": "content-type": "content-type": "coplication / json "}, success: function (res) {fn (res);}});} else {// simulation data var res = mock.mock ({'error_code': ',' error_msg ':', 'Data | 10': [{'ID | +1': 1, 'IMG': "@Image ('200x100', '# 4a7bf7', '# fff', 'Pic ') ",' Title ':' @ctit (3, 8) ',' City ':" @county (true) ",' stock_num ':' @Integer (0,100) ', // Stock number' Marketing_Start ' : '@datetime ()', 'Marketing_Stop': '@now ()', 'price': '@integer (100, 2000)', // Current price, unit: points' original_price ':' @Integer (100, 3000) '}]}) // Output result // console.log (Json.Stringify (RES, NULL, 2)) fn (res);}} module.exports =} module.exports = {ajax: ajax}   
INDEX.JS page

// index.js // Get application example var app = getApp () var API = Require (‘ ../../ utils / api.js’) Page ({data: {}, online: function () {console.log (‘onload’) Var That = this // Using Mock Api.ajax (”, Function (RES) {// Here you can get analog RES Console.log (RES) That.SetData ({List: Res. Data)})}}); console.log (this.data.list)}})
 中] .w   

{{item.title}}
{ipem.city}}
   {ipem.marketing_start}}              The above is all the contents of this article, I hope to help everyone, and I hope you will support Tumi Clouds. 
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment