请求方式使用的是
axios,在main.js中添加baseURL
在下面配置中加上
axios.defaults.baseURL = 'http://xxxx:18081';即可
Vue.use(VueAxios, axios)
axios.defaults.baseURL = 'http://localhost:18081';
再次发送请求时就不用带前缀了
this.axios(
{
url: '/api-admin/user/selectServiceOrSenderTest/1/',
method: 'GET',
data: {}
}
).then(response => {
console.log(response)
})
本文介绍了如何在Vue项目中使用axios全局配置基础URL,通过在main.js中添加axios.defaults.baseURL,使得后续的HTTP请求不再需要手动添加服务器地址。例如设置为'http://localhost:18081'后,发送GET请求时可以直接指定相对路径,如'/api-admin/user/selectServiceOrSenderTest/1/',从而提高代码的简洁性和可维护性。
1万+





