第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Axios:用戶在登錄前嘗試

Axios:用戶在登錄前嘗試

當(dāng)我使用正確的電子郵件/密碼發(fā)送“EnvioLogin”時(shí),我從“/login”獲取訪問(wèn)令牌,但之后我無(wú)法獲取“/users”,只有在我在瀏覽器中檢查時(shí),我才得到:https://i . stack.imgur.com/yBJK0.jpg https://i.stack.imgur.com/bWQEG.jpg用戶嘗試登錄后如何運(yùn)行創(chuàng)建的掛鉤?import axios from "axios";export default {  name: "login",  data() {    return {      showError: false,      email: "",      password: "",    };  },     async created() {    const response = await axios.get("api/users", {      headers: {        Authorization: "Bearer " + localStorage.getItem("token")      }    });    console.log(response);  },  methods: {    async EnvioLogin() {      try {        const response = await axios.post("api/auth/login", {          email: this.email,          password: this.password,        });        localStorage.setItem("token", response.data.token);        const status = JSON.parse(response.status);        if (status == "200") {          console.log(response);          this.$router.push("intermediorotas");          this.showLogin = false;        }      } catch (error) {        this.showError = true;        setTimeout(() => {          this.showError = false;        }, 2000);      }    },  },
查看完整描述

1 回答

?
慕哥9229398

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊

創(chuàng)建的鉤子內(nèi)的代碼可以位于名為的單獨(dú)方法中g(shù)etUsers,然后在方法中調(diào)用它EnvioLogin:



import axios from "axios";

export default {

  name: "login",



  data() {

    return {

      showError: false,

      email: "",

      password: "",

    };

  },

  created() {

   this.getUsers();

  },


  methods: {

   async getUsers(){

   const response = await axios.get("api/users", {

      headers: {

        Authorization: "Bearer " + localStorage.getItem("token")

      }

    });


    console.log(response);

  },

    async EnvioLogin() {

      try {

        const response = await axios.post("api/auth/login", {

          email: this.email,

          password: this.password,

        });

        localStorage.setItem("token", response.data.token);

        const status = JSON.parse(response.status);

        if (status == "200") {

         this.getUsers();

          console.log(response);

          this.$router.push("intermediorotas");

          this.showLogin = false;

        }

      } catch (error) {

        this.showError = true;

        setTimeout(() => {

          this.showError = false;

        }, 2000);

      }

    },

  },


查看完整回答
反對(duì) 回復(fù) 2023-09-14
  • 1 回答
  • 0 關(guān)注
  • 93 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)