一、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里进一步处理数据。