the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > can be in after the success of the login, each will modify IP address to keep to the localStorage, The ip address in localStorage is then called in the instance encapsulated by axios for access.
Example code is as follows:
// 将ip地址保存到localStorage中
localStorage.setItem('serviceIp', '192.168.1.100');
localStorage.setItem('serviceCode', '8080');
// 从localStorage中获取ip地址
const serviceIp = localStorage.getItem('serviceIp');
const serviceCode = localStorage.getItem('serviceCode');
// 封装axios实例
const service = axios.create({
baseURL: http://${serviceIp}:${serviceCode}/smartApp,
timeout: 5000
});
// 在每次请求时使用封装的axios实例
service.get('/api/data').then(response => {
console.log(response.data);
}).catch(error => {
console.log(error);
});