开发环境:react
现在做到了,点击后在当前页面使用fetch方法get一个链接然后跳转到目标页面。
如何保留当前页面,打开一个新标签页使用fetch方法get一个链接,然后跳转到目标页面。
当前代码:
getService(API_PREFIX + '/services/user/loginLingShen', data2 => {
console.log(data2);
fetch(data2.result, { //fetch方法get的链接
method: 'GET',
mode: 'no-cors',
credentials: 'include',
cache: 'no-store',
headers: {
'Content-Type': 'application/json',
},
}).then(function (response) {
return response.text().then((json) => {
window.location='http://www.linksame.com'; //get完之后跳转到这个页面
});
}).catch((error) => {
console.log(error);
});