0
Follow
0
View

How to change the ip address after each time

ctctcct3 注册会员
2023-02-27 12:30

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);
});

dc200687 注册会员
2023-02-27 12:30

Change the serviceIp of BaseUrl to localstorage.getItem("serviceIp')

About the Author

Question Info

Publish Time
2023-02-27 12:30
Update Time
2023-02-27 12:30