流浪のwolf

卷帝

导航

element表单校验 【登录】

   async btnOK () {
      // 1. 表单校验 (调用表单的校验方法获取校验结果)
      //   this.$refs.formRef.validate(function (valid) {
      //     console.log(valid);
      //   });
      try {
        await this.$refs.formRef.validate();
      } catch (error) {
        return console.log(error);
      }
      // 2. 数据是否要加工处理
      // 3. 发生请求请求
      this.isLoading = true;
      // 这里异步的;如果不写awiat则会出现权限控制逻辑错误
      try {
        await this.$store.dispatch("user/loginAction", this.formData);
        this.$router.push("/");
      } catch (error) {
        this.isLoading = false;
      }

      // 调用获取用户资料的action,因为这里已经有了token
      // 这里写,必须要重新登录才可以!
      // await this.$store.dispatch('user/getUserProfileAction');
      // 4. 跳转主页(登录成功才可以跳转)
      this.isLoading = false;
    },

 

posted on 2023-05-13 07:37  流浪のwolf  阅读(6)  评论(0编辑  收藏  举报