搞一个平台,嵌入多个项目,登录接口处需要拿到所有项目的token,后端不想搞新接口,那前端来处理,登录页面同时调取多个平台的接口,使用promise.all来处理
            
            
              javascript
              
              
            
          
            if (valid) {
        // yiheng
        const yhData = {
          account: this.loginForm.username,
          password: this.loginForm.password,
        };
        let p1 = new Promise((resolve, reject) => {
          axios({
            method: "post",
            url: "/yh/auth/login",
            data: yhData,
          })
            .then((res) => {
              this.TokenSetting("YHToken", res.data.data.token);
              resolve(res);
            })
            .catch((e) => {
              reject("发生错误");
            });
        });
        // yifu
        const yfData = {
          username: this.loginForm.username,
          password: this.loginForm.password,
        };
        let p2 = new Promise((resolve, reject) => {
          axios({
            method: "post",
            url: "/api/v1.0/users/login",
            data: yfData,
          })
            .then((res) => {
              this.TokenSetting("YFToken", res.data.data.access_token);
              resolve(res);
            })
            .catch((e) => {
              reject("发生错误");
            });
        });
        Promise.all([p1, p2])
          .then((results) => {
            this.$router.push({
              path: "/applicationSoftware",
            });
          })
          .catch((e) => {
            this.$message.error(e);
          });
      } else {
        return false;
      }
    });
  }
  TokenSetting(TokenKey: string, TokenVal: string) {
    localStorage.setItem(TokenKey, TokenVal);
  }
        涉及到跨域问题,在vue.config,js文件中配置
            
            
              javascript
              
              
            
          
           devServer: {
    // open: true, // 配置项目在启动时自动在浏览器打开
    proxy: {
        '/yh' : { // '/api'是代理标识,一般是每个接口前的相同部分
            target: "http://192.168.5.58:8002", // 请求地址,一般是服务器地址
            changeOrigin: true, // 是否进行跨域
            // pathRewrite: { // pathRewrite的作用是把请求接口中的 '/api'替换掉,一般是替换为空""
            //     '^/api':""
            // }
        },
        '/api':{
          target: "http://192.168.5.52:8021", // 请求地址,一般是服务器地址
          changeOrigin: true, // 是否进行跨域
        }
    },
  }