前端菜狗日记之promise的使用(uniapp和vue中)

一、uniapp

getMemberDetail() {
				//获取详情
				const parmas = {
					callback: 'get_member_detail',
					uuKey: true,
					params: {
						token: this.$store.state.token,
						loginType: this.$store.state.loginType,
						id: this.form.id,
					}
				};
				return this.$store.dispatch('requestData', parmas)
					.then(res => {
						console.log(res, '会员详情')
						if (!res) {
							return
						}
						if (res.data.code == 200) {
							this.form = res.data.data;
							this.form.member_card = this.form.member_card == null?'':this.form.member_card;
							res.data.data.birthday = res.data.data.birthday ? res.data.data.birthday : '';
							this.old = JSON.parse(JSON.stringify(res.data.data));
							this.form.birthday = this.form.birthday ? this.form.birthday : '';
							this.sexIndex = this.form.sex == 1 ? 0 : 1;
							let data = this.memberLevels.filter((i, k) => {
								if (i.id == this.form.level_id) {
									this.levelIndex = k;
								}
								return i.id == this.form.level_id
							});
						}
					})
			},

二、vue
一个函数使用promise的方式返回值例如:

  getSuperShopFunctionStatus(user_info_id,shopid){
            //超级管理员获取门店功能权限列表
              return new Promise((resolve,reject)=> {
                        postData({
                            url:'/api/v1/super_shop_function_status',
                            method:'GET',
                            data:{
                              user_info_id: user_info_id,//管理员id
                              shopid:shopid,//门店id(传空,则所有门店)
                              status:'1'//状态 0:关闭 1:开启(传空则表示获取全部)
                            },
                        },{
                            success:res => {
                              if(res.code==200){
                              console.log(res.data,'功能权限列表')
                              if(res.data&&res.data.length!==0){
                                  resolve(res.data);
                              }else if(res.data.length==0){
                                 console.log('没有数据')
                                } 
                              }
                            }
                        })
                    })
          },

在resolve(这里的是返回值)在外部调用时接收使用 async await :

 async openEditorFunction(row){
            //开启编辑功能
         console.log(row,'打开编辑')
         this.openDialog3 = true
         let user_info_id = this.user_info_id
         let shopid = row.row.id
         this.shopid = shopid
         let functionStatus = await his.getSuperShopFunctionStatus(user_info_id,shopid)
         console.log(functionStatus,'functionStatus外面接收打印')
      },

在接收的functionStatus里进一步处理数据。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值