如何用fastmock动态获取参数

一.在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)
							    
							}
				})
			},

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mr.指尖舞者

如果帮助到了你,请给点赞助支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值