Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

如何判断方法A执行完毕,之后再执行方法B

vue mountede里面的两个方法 必须要确保 this.myonLoad执行完毕之后,再执行this.login_onclick
`

 async mounted() {
  await this.myonLoad();
  this.login_onclick();
},

`

this.myonLoad 返回一个promise对象

`

 myonLoad() {
    return new Promise((resolve, reject) => {
      try {
        var s_pnp = new SoftKey3W();
        s_pnp.Socket_UK.onopen = function () {
          bConnect = 1; //代表已经连接,用于判断是否安装了客户端服务
        };

        //在使用事件插拨时,注意,一定不要关掉Sockey,否则无法监测事件插拨
        s_pnp.Socket_UK.onmessage = function got_packet(Msg) {
          var PnpData = JSON.parse(Msg.data);
          if (PnpData.type == "PnpEvent") {
            //如果是插拨事件处理消息
            if (PnpData.IsIn) {
              alert(
                "UKEY已被插入,被插入的锁的路径是:" + PnpData.DevicePath
              );
            } else {
              alert(
                "UKEY已被拨出,被拨出的锁的路径是:" + PnpData.DevicePath
              );
            }
          }
        };

        s_pnp.Socket_UK.onclose = function () {};
      } catch (e) {
        alert(e.name + ": " + e.message);
        return false;
      }
    });
  },

`


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
myonLoad() {
    return new Promise((resolve, reject) => {
      try {
        var s_pnp = new SoftKey3W();
        s_pnp.Socket_UK.onopen = function () {
          bConnect = 1; //代表已经连接,用于判断是否安装了客户端服务
        };

        //在使用事件插拨时,注意,一定不要关掉Sockey,否则无法监测事件插拨
        s_pnp.Socket_UK.onmessage = function got_packet(Msg) {
          var PnpData = JSON.parse(Msg.data);
          if (PnpData.type == "PnpEvent") {
            //如果是插拨事件处理消息
            if (PnpData.IsIn) {
              alert(
                "UKEY已被插入,被插入的锁的路径是:" + PnpData.DevicePath
              );
            } else {
              alert(
                "UKEY已被拨出,被拨出的锁的路径是:" + PnpData.DevicePath
              );
            }
          }
        };
        // ******************** 看这里 ********************
        // 内部处理完后执行一下就可以了
        resolve(true);

        s_pnp.Socket_UK.onclose = function () {};
      } catch (e) {
        alert(e.name + ": " + e.message);
        return false;
      }
    });
  },

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...