Easy mock學習

1.Easy mock官網進行註冊登陸java

2.建立我的項目小程序

 

3.建立接口 預覽接口api

 

 引入mock.js 返回值支持隨機生成 數組

語法列子1:dom

{
"success": true,
"data": {
"projects|3-10": [{   //在3到10之間隨機取數
"name": "演示用",
"url": "@url",  //隨機生成URL地址
"email": "@email", //隨機生成郵箱
"address": "@county(true)",//隨機生成地址
"string|1-10": "★", //字符隨機遞增1到10個
"number|1-100": 100,//取1到100的隨機數
"boolean|1-2": true,//隨機取布爾值
"object|2": { //在數組裏面隨機輸出兩個
"310000": "上海市",
"320000": "江蘇省",
"330000": "浙江省"
}
}]
}
}測試

 語法列子2:url

{
"resultCode": 999999,
"resultMessage": "success",
"data": {

"productList": () => {
var productList = [{
"productId": "1161102724370108419aaaaaaaaaaaaa",
"brand": "阿迪達斯Adidas",
"tagPrice": 21800,
"category": "男益生菌/初乳",
"picture": ["http://devdevnew.oss.aikucun.com/21529a91bb71f55ff0c447181c24c5acc6e91430_1564472487604_92.jpg", "http://devdevnew.oss.aikucun.com/2dfc8caa93a1a23dd0bc420bc58c8ecf8f3497b6_1564472487612_83.jpg", "http://devdevnew.oss.aikucun.com/1c8ca7e3766331e5837b84d6e4a7369809e32dee_1564472487594_84.jpg", "http://devdevnew.oss.aikucun.com/ca54bf096bf96ac4d91436a4323f407f126673fd_1564472487585_62.jpg"],
"brandSizeUrl": "http://devdevnew.oss.aikucun.com/ca54bf096bf96ac4d91436a4323f407f126673fd_1564472487585_62.jpg",
"price": 13000,
"name": "商戶雲移動版測試商品【輔食/白的/市場價218】",
"settlementPrice": 12000,
"profit": 1000,
"skusAttributeList": [{
"attributeName": "尺碼",
"attributeValue": "20"
}, {
"attributeName": "顏色",
"attributeValue": "白的"
}],
"skuList": [{
"skuId": "1161102724370108419aaaaaaaaaaaaa",
"attributeList": [{
"attributeName": "顏色",
"attributeValue": "白的"
}, {
"attributeName": "尺碼",
"attributeValue": "20"
}]
}],
"description": "2600三、 阿迪達斯Adidas男益生菌/初乳-¥130.00\n尺碼 20 \n款式 商戶雲移動版測試商品【輔食/白的/市場價218】\n款號 989524",
"weight": "20.0",
"volume": "20.0"
}, {
"productId": "1161102724370108419aaaaaaaaaaaaa",
"brand": "阿迪達斯Adidas",
"tagPrice": 21801,
"category": "男益生菌/初乳",
"picture": ["http://devdevnew.oss.aikucun.com/21529a91bb71f55ff0c447181c24c5acc6e91430_1564472487604_92.jpg", "http://devdevnew.oss.aikucun.com/2dfc8caa93a1a23dd0bc420bc58c8ecf8f3497b6_1564472487612_83.jpg", "http://devdevnew.oss.aikucun.com/1c8ca7e3766331e5837b84d6e4a7369809e32dee_1564472487594_84.jpg", "http://devdevnew.oss.aikucun.com/ca54bf096bf96ac4d91436a4323f407f126673fd_1564472487585_62.jpg"],
"brandSizeUrl": "http://devdevnew.oss.aikucun.com/ca54bf096bf96ac4d91436a4323f407f126673fd_1564472487585_62.jpg",
"price": 13000,
"name": "商戶雲移動版測試商品【輔食/白的/市場價218】",
"settlementPrice": 12000,
"profit": 1000,
"skusAttributeList": [{
"attributeName": "尺碼",
"attributeValue": "20"
}, {
"attributeName": "顏色",
"attributeValue": "白的"
}],
"skuList": [{
"skuId": "1161102724370108419aaaaaaaaaaaaa",
"attributeList": [{
"attributeName": "顏色",
"attributeValue": "白的"
}, {
"attributeName": "尺碼",
"attributeValue": "20"
}]
}],
"description": "2600三、 阿迪達斯Adidas男益生菌/初乳-¥130.00\n尺碼 20 \n款式 商戶雲移動版測試商品【輔食/白的/市場價218】\n款號 989524",
"weight": "20.0",
"volume": "20.0"
}, {
"productId": "1161102724370108419aaaaaaaaaaaaa",
"brand": "阿迪達斯Adidas",
"tagPrice": 21802,
"category": "男益生菌/初乳",
"picture": ["http://devdevnew.oss.aikucun.com/21529a91bb71f55ff0c447181c24c5acc6e91430_1564472487604_92.jpg", "http://devdevnew.oss.aikucun.com/2dfc8caa93a1a23dd0bc420bc58c8ecf8f3497b6_1564472487612_83.jpg", "http://devdevnew.oss.aikucun.com/1c8ca7e3766331e5837b84d6e4a7369809e32dee_1564472487594_84.jpg", "http://devdevnew.oss.aikucun.com/ca54bf096bf96ac4d91436a4323f407f126673fd_1564472487585_62.jpg"],
"brandSizeUrl": "http://devdevnew.oss.aikucun.com/ca54bf096bf96ac4d91436a4323f407f126673fd_1564472487585_62.jpg",
"price": 13000,
"name": "商戶雲移動版測試商品【輔食/白的/市場價218】",
"settlementPrice": 12000,
"profit": 1000,
"skusAttributeList|0": [{
"attributeName": "尺碼",
"attributeValue": "20"
}, {
"attributeName": "顏色",
"attributeValue": "白的"
}],
"skuList": [{
"skuId": "1161102724370108419aaaaaaaaaaaaa",
"attributeList": [{
"attributeName": "顏色",
"attributeValue": "白的"
}, {
"attributeName": "尺碼",
"attributeValue": "20"
}]
}],
"description": "2600三、 阿迪達斯Adidas男益生菌/初乳-¥130.00\n尺碼 20 \n款式 商戶雲移動版測試商品【輔食/白的/市場價218】\n款號 989524",
"weight": "20.0",
"volume": "20.0"
}]
let size = 2

let pSize = productList.length
if (pSize < size) {
size = pSize
}
// let size = Math.ceil(Math.random() * size)
let start = Math.floor(Math.random() * pSize)
let end = start + size
if (end >= pSize) {
end = pSize
start = pSize - size
}
return productList.slice(start, end)
}
}

}3d

 

 

4.java項目中使用easy mock blog

將相關項目配置文件中修改openapi配置地址,改爲本身mock的地址接口

5. 本地搭建easy mock 待補充

6. easy mock在小程序中的應用 待補充

相關文章
相關標籤/搜索