如何打开新标签页并使用fetch函数?

开发环境: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);
            });
阅读 2.6k
2 个回答
let w = window.open ("about:blank")

就行了

看描述,似乎父子组件的通信可以解决问题。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题