免费国产欧美国日产_少妇AV一区二区三区无码_蜜桃精品av无码喷奶水小说_jk18禁网站视频_精产国品一二三级产品区别_被夫の上司に犯波多野结衣_78m成人手机免费看_最爽最刺激18禁视频_偷偷色噜狠狠狠狠的777米奇

易優(yōu)GEO 重磅上線 ~ 一站式GEO優(yōu)化工具,讓豆包、文心一言、DeepSeek 在回答中主動(dòng)推薦你的品牌,搶占AI流量入口!  點(diǎn)擊查看

小程序模板網(wǎng)

微信小程序 + mock.js 實(shí)現(xiàn)后臺(tái)模擬及調(diào)試

發(fā)布時(shí)間:2018-04-25 09:07 所屬欄目:小程序開發(fā)教程

一、創(chuàng)建小程序項(xiàng)目

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

api.js:配置模擬數(shù)據(jù)和后臺(tái)接口數(shù)據(jù),通過 DEBUG = true;//切換數(shù)據(jù)入口

let API_HOST = "http://xxx.com/xxx";
let DEBUG = true;//切換數(shù)據(jù)入口
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 {
        // 模擬數(shù)據(jù)
        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)',//庫存數(shù)量  
                'marketing_start': '@datetime()',
                'marketing_stop': '@now()',
                'price': '@integer(100,2000)',//現(xiàn)價(jià),單位:分  
                'original_price': '@integer(100,3000)'
            }]  
        })
        // 輸出結(jié)果
       // console.log(JSON.stringify(res, null, 2))
        fn(res);
    }
}
module.exports = {
    ajax: ajax
}

index.js頁面

index.wxml

頁面顯示



易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.szcjxy.com/wxmini/doc/course/23957.html 復(fù)制鏈接 如需定制請(qǐng)聯(lián)系易優(yōu)客服咨詢: 點(diǎn)擊咨詢
在線客服