一.在fastmock中写json
只有传入的id为零才能相应数据
{
"code": "0000",
"data": function({_req,Mock}){
let body=_req.body;
if(body.id==="0"){
return Mock.mock({
meta:{
status:200,
msg:'登陆成功'
},
message:{
goods_id:0,
goods_name:'华凌空调 新一级能效 变频冷暖 超大风口 1.5匹 客厅卧室空调挂机 以旧换新 智能遥控 KFR-35GW/N8HE1',
goods_price:2230,
goods_number:100,
goods_weight:100,
goods_prics:[
'https://img13.360buyimg.com/n1/jfs/t1/205480/25/18908/243494/61bada58E60b4323a/c5b437bd3d26178b.jpg',
'https://img13.360buyimg.com/n1/jfs/t1/138589/37/26751/298687/61bada4dEd9a781ea/88c405887d46bb35.jpg',
'https://img13.360buyimg.com/n1/jfs/t1/164870/32/27379/344825/6242dec8E24c2b0b7/d098cdffca91fe75.jpg',
],
goods_many:[
'https://img.alicdn.com/imgextra/i1/2206358644076/O1CN01MiFa7Y1fyr6EJ6Wah_!!2206358644076.jpg',
'https://img.alicdn.com/imgextra/i2/2206358644076/O1CN018Bx3ug1fyr6784fbD_!!2206358644076.jpg',
'https://img.alicdn.com/imgextra/i1/2206358644076/O1CN01gRkgwp1fyr6Dddk67_!!2206358644076.jpg',
'https://img.alicdn.com/imgextra/i2/2206358644076/O1CN01Z5Ilm61fyr6I2xYPg_!!2206358644076.jpg',
'https://img.alicdn.com/imgextra/i3/2206358644076/O1CN01QzhOkN1fyr7HKaXOe_!!2206358644076.jpg',
]
},
});
}else{
return Mock.mock({
mes:'登录失败',
sciiess:false
})
}
}
}
二以uniapp中请求数据为例
getgoodsdetail(){
console.log(this.goods_id)
uni.request({
url:'https://www.fastmock.site/mock/3365ffb7cdc082951bfb1e74fcbdd547/shop/detail',
method:'POST',
data:{
id:this.goods_id
},
success:(res)=>{
this.goodsdetail.name=res.data.data.message.goods_name
this.goodsdetail.price=res.data.data.message.goods_price
this.prics=res.data.data.message.goods_prics
this.goodsdetail.number=res.data.data.message.goods_number
this.goodsdetail.weight=res.data.data.message.goods_weight
this.many=res.data.data.message.goods_many
console.log(this.many)
}
})
},