账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vuex状态管理 action的问题
    • 2019-10-14 00:00
    • 11
    30
    0

    题目描述

    代码如下:怎么等待action这些操作都完成之后,再执行vue组件中的异步函数

    题目来源及自己的思路

    问题来源于正在开发的项目

    相关代码

    // 请把代码文本粘贴到下方(请勿用图片代替代码)
    const actions = {

    async login({ commit }, userInfo) {
        my.getAuthCode({
            scopes: 'auth_user', // 主动授权:auth_user,静默授权:auth_base。或者其它scope
            success: (res) => {
                if (res.authCode) {
                    return  Vue.prototype.$http.getToken(res.authCode).then(result => {
                        return result
                    }).then(result=>{
                        my.getAuthUserInfo({
                            success: (userInfo) => {
                                commit( 'ALIUSERID' , result.data.userId);
                                commit('AVATAR', userInfo.avatar);
                                commit('NICKNAME', userInfo.nickName);
                                var _data = {
                                    nick: userInfo.nickName ? userInfo.nickName : '',
                                    ico: userInfo.avatar ? userInfo.avatar : '',
                                    aliUserId: result.data.userId,
                                    noLoginType: 4,
                                    device: 'ali-mini-program',
                                }
                                Vue.prototype.$http.postLogin(_data).then(res => {
                                    var userCname = res.userinfo.username;
                                    var userPhone = res.userinfo.phone;
                                    commit('USERID', userCname);
                                    commit('USERPHONE', userPhone);
                                })
                            }
                        });
                    })
                }
            },
        });
    }

    }

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部