GET http://localhost:3000/api/auth/user/:id 401(未經授權)
P粉232409069
P粉232409069 2024-03-19 16:49:19
0
1
417

我將 vue3 與 axios 和 prisma 結合使用,但在獲取使用者資訊時遇到問題。

我的郵差要求可以(http://localhost:3000/api/auth/user/7),但我的 axios 要求不行。

你能幫我嗎?

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

        
    }

P粉232409069
P粉232409069

全部回覆(1)
P粉322106755

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);
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!