网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

微信小程序 + mock.js 實現后臺模擬及調試

發布時間:2018-04-25 09:07 所屬欄目:小程序開發教程

一、創建小程序項目

mock.js 從 https://github.com/nuysoft/Mock/blob/refactoring/dist/mock.js 下載

api.js:配置模擬數據和后臺接口數據,通過 DEBUG = true;//切換數據入口

let API_HOST = "http://xxx.com/xxx";
let DEBUG = true;//切換數據入口
var Mock = require('mock.js')
function ajax(data = '', fn, method = "get", header = {}) {
    if (!DEBUG) {
        wx.request({
            url: config.API_HOST + data,
            method: method ? method : 'get',
            data: {},
            header: header ? header : { "Content-Type": "application/json" },
            success: function (res) {
                fn(res);
            }
        });
    } else {
        // 模擬數據
        var res = Mock.mock({
            'error_code': '',
            'error_msg': '',
            'data|10': [{
                'id|+1': 1,
                'img': "@image('200x100', '#4A7BF7','#fff','pic')",
                'title': '@ctitle(3,8)',
                'city': "@county(true)",
                'stock_num': '@integer(0,100)',//庫存數量  
                'marketing_start': '@datetime()',
                'marketing_stop': '@now()',
                'price': '@integer(100,2000)',//現價,單位:分  
                'original_price': '@integer(100,3000)'
            }]  
        })
        // 輸出結果
       // console.log(JSON.stringify(res, null, 2))
        fn(res);
    }
}
module.exports = {
    ajax: ajax
}

index.js頁面

index.wxml

頁面顯示



易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/23957.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×