数据存本地 localStorage Cookie session

本地存取:
哪里用在哪里取

data() {
    return {
      loginForm: {
        userName: "11111111",
        password: "123456",
      },
  }
  async submitForm(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          // 存用户名与密码
          localStorage.setItem("USERNAME",JSON.stringify(this.loginForm.userName));
          localStorage.setItem( "PASSWORD",JSON.stringify(this.loginForm.password));
          // 用户登录
          const data = {
            USERNAME: this.loginForm.userName,
            PASSWORD: this.loginForm.password,
          };
          //loginAPI 接口
          const res = await loginAPI(data);
          // 设置SSOTOKEN变量
          const SSOTOKEN = res.data.SSOTOKEN;
          // 存SSOTOKEN
          localStorage.setItem("SSOTOKEN", JSON.stringify(SSOTOKEN));
          // 存USERDN
          localStorage.setItem("USERDN",res.data.UserDN)
          // 统一登录
          const registerData = {
            password: SSOTOKEN,
            localip: "192.168.2.10",
            ssoflag: "true",
            deviceID: Math.random() * 10 ** 17,
          };
          const res1 = await registerLoginAPI(
            registerData,
            this.loginForm.userName
          );
          // console.log("SESSION:" + res1.data.session);
          const SESSION = res1.data.session;
          // 存SESSION
          localStorage.setItem("SESSION", JSON.stringify(SESSION));
          // 建立websocket连接
          connect(SSOTOKEN, SESSION, res.data.UserDN);
          // 清空表单
          this.resetForm("loginForm");
          // 提示
          this.$message.success("登录成功");
          // 跳转
          this.$router.push("home/chat");
        }
      });
    },

你可能感兴趣的:(前端,javascript,开发语言)