zoukankan      html  css  js  c++  java
  • mock.js 学习

    安装

    npm install mockjs

    使用

    // 引入
    import Mock from 'mockjs'

    Mock.setup({
    timeout: '200 - 400'
    })

    const Random = Mock.Random;
    // 导航信息
    const produceNewsData = function () {
    let articles = [];
    for (let i = 0; i < 20; i++) {
    let newArticleObject = {
    id: i,
    title: Random.csentence(2, 5),
    thumbnail_pic_s: Random.dataImage('80*80', 'mock的图片'),
    // author_name: Random.cname(),
    date: Random.date() + ' ' + Random.time()
    }
    articles.push(newArticleObject)
    }

    return {
    articles: articles
    }
    }

    // 推荐商家
    const recommendBusinessman = function () {
    let articles = [];
    for (let i = 0; i < 40; i++) {
    let newArticleObject = {
    id: i,
    title: Random.csentence(2, 12),
    thumbnail_pic_s: Random.dataImage('65*65', 'mock的图片'),
    brand: Random.boolean(),
    basePrice: Random.natural(0, 100),
    expressPrcie: Random.natural(0, 10),
    popularity: Random.boolean(),
    }
    articles.push(newArticleObject)
    }

    return {
    articles: articles
    }
    }


    // 订单列表
    const orderList = function () {
    let articles = [];
    for (let i = 0; i < 40; i++) {
    let newArticleObject = {
    id: i,
    title: Random.csentence(2, 12),
    orderState: Random.boolean(),
    productInfo: Random.csentence(2, 12),
    productPrice: Random.natural(0, 10),
    date: Random.date() + ' ' + Random.time()
    }
    articles.push(newArticleObject)
    }

    return {
    articles: articles
    }
    }


    // 我的信息
    const myInfo = function () {
    let articles = [];
    for (let i = 0; i < 1; i++) {
    let newArticleObject = {
    userName: Random.csentence(2, 5),
    userTel: '17748682298',
    userRedPacketNum: Random.csentence(0, 12),
    userGoldNum: Random.natural(0, 10),
    date: Random.date() + ' ' + Random.time()
    }
    articles.push(newArticleObject)
    }

    return {
    articles: articles
    }
    }

    const userInfoWord = {
    userName: '17748682298',
    userPassWord: '187521ZZ'
    }
    //验证登陆信息
    function loginFun(prarms) {
    const prarmsObj = prarms.body
    let splitObj = prarmsObj.split("=")
    prarms = {
    name: splitObj[1].split('&')[0],
    userWord: splitObj[2]
    }
    if (userInfoWord.userName === prarms.user || prarms.userWord === userInfoWord.userPassWord) {
    return {
    code: 1,
    text: '登录成功'
    }
    } else {
    return {
    code: 2,
    text: '用户名或密码错误'
    }
    }
    }

    // 订单列表
    Mock.mock('/orderlist', /post|get/i, orderList)

    // 导航信息
    Mock.mock('/nav', /post|get/i, produceNewsData)

    // 推荐商家
    Mock.mock('/recommendBusinessman', /post|get/i, recommendBusinessman)

    // 我的信息
    Mock.mock('/myinfo', /post|get/i, myInfo)

    // 推荐登陆
    Mock.mock('/loginfun', /post|get/i, loginFun)
  • 相关阅读:
    蛙蛙推荐:改进了一个DBAccess类,顺便说说啥是线程安全
    蛙蛙推荐:SQLServer优化资料整理
    快速配置Eclipse3.1.1+Tomcat5.0+Lomboz dodo
    建立asp.net应用程序提示:无法与服务器建立连接 dodo
    tomcat连接sqlserver配置 dodo
    如何让DNN页面中的html控件中的文本项显示为中文? dodo
    DropDownList 不能有多个项被选定 dodo
    转换DATAREADER为 dataset dodo
    使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件 dodo
    ASP.NET的WEB项目不能添加WEB用户控件的解决 dodo
  • 原文地址:https://www.cnblogs.com/ralapgao/p/12090028.html
Copyright © 2011-2022 走看看