簡體   English   中英

GET http://localhost:3000/api/auth/user/:id 401(未授權)

[英]GET http://localhost:3000/api/auth/user/:id 401 (Unauthorized)

我將 vue3 與 axios 和 prisma 一起使用,但在獲取用戶信息時遇到問題。

我的郵遞員請求沒問題(http://localhost:3000/api/auth/user/7),但我的 axios req 不是。

你能幫我嗎 ?

        async created () {
        const response = await axios.get('http://localhost:3000/api/auth/user/:id', { 
            headers: {
                Authorization: 'Bearer ' + localStorage.getItem('token')
            }
            
        });
        console.log('ici');

        
    }

Axios 不支持 URL 參數。

一種解決方案是使用模板字符串來構建請求 URL。

例如:

function getID(id) {
    const response = await axios.get(`http://localhost:3000/api/auth/user/${id}`,{ 
          headers: {
              Authorization: 'Bearer ' + localStorage.getItem('token')
          }  
    });
}

// getID(7);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM