zoukankan      html  css  js  c++  java
  • MOCK.js的用法

    初用mock的体会

    先上代码,如下,模拟数据的js。mock可以模拟目前业务所需的所有数据,属性key/生成规则rules/属性值value,还有一些指定类型数据的随机生成函数@cname @dreess等等 ,对用javascript开发客户端的人员来说,完全解决了模拟数据的问题,还是很不错的。使用也很方便。

    ...
    		var Mock = require('../../utils/mock.js')
    		Mock.mock('http://uiui.com',{
    			"dataArry|50":[
    				{
    				'name|3':'fei',//这个定义数据的模板形式下面会介绍
    				'age|20-30':25,
    				'job':'program',
    				 "shopAddress": "@county(true)", //随机生成地址
    				 "shopMsg": "@ctitle(10)", //生成商品信息,长度为10个汉字
    				 "shopName": "@cname",//生成商品名 , 都是中国人的名字
    				 "shopTel": /^1(5|3|7|8)[0-9]{9}$/,//生成随机电话号
    				 "shopAddress": "@county(true)", //随机生成地址
    				 "shopStar|1-5": "★", //随机生成1-5个星星
    				 "salesVolume|30-1000": 30, //随机生成商品价格 在30-1000之间
    				 "shopLogo": "@Image('100x40','#c33', '#ffffff','艺术')", //生成随机图片,大小/背景色/字体颜色/文字信息
    				}
    			]
    		})
    	        uni.request({
    		    url: 'http://uiui.com', 
    			method:"get",
    		    success: (res) => {
    		        console.log(res.data);
    		    },
    			fail:(error)=>{
    				console.log(error);
    			}
    		})
    

    ...

  • 相关阅读:
    球员岁月齐祖辉煌,执教生涯尤胜当年
    UVM序列篇之一:新手上路
    *2-3-7-加入field_automation机制
    2.3.6-加入scoreboard
    *2_3_5_加入reference model
    *2.3.4_封装成agent
    *2.3.3-加入monitor
    android的wake_lock介绍
    linux常用命令一些解释
    linux wc命令的作用。
  • 原文地址:https://www.cnblogs.com/aryu/p/12752447.html
Copyright © 2011-2022 走看看