我將 vue3 與 axios 和 prisma 結(jié)合使用,但在獲取用戶信息時遇到問題。
我的郵遞員請求可以(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'); }
一種解決方案是使用模板字符串來構(gòu)建請求 URL。
例如:
function getID(id) { const response = await axios.get(`http://localhost:3000/api/auth/user/${id}`,{ headers: { Authorization: 'Bearer ' + localStorage.getItem('token') } }); } // getID(7);