I'm using vue3 with axios and prisma but I'm having trouble getting user information.
My postman request works (http://localhost:3000/api/auth/user/7), but my axios request does not.
Can you help me?
async created () { const response = await axios.get('http://localhost:3000/api/auth/user/:id', { headers: { Authorization: 'Bearer ' localStorage.getItem('token') } }); console.log('ici'); }
P粉3221067552024-03-20 15:37:00
axios does not support URL parameters.
One solution is to use template strings to build the request URL.
For example:
function getID(id) { const response = await axios.get(`http://localhost:3000/api/auth/user/${id}`,{ headers: { Authorization: 'Bearer ' localStorage.getItem('token') } }); } // getID(7);