我将 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');
} Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
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);