我使用React路由器链接在新窗口中渲染组件,现在如何将数据传递给这个新组件。我想要传递的数据是JSON数据,所以如果我将其作为参数或查询传递,它已显示在URL中。
在新窗口中打开时,还有其他选项可用于传递数据吗?
答案 0 :(得分:0)
使用其中一个较新的选项:
索引资料
postMessage(ScrollIntoView
)
<script>
var popup = window.open('data:text/html;charset=utf-8;base64,PHNjcmlwdD5mdW5jdGlvbiByZWNlaXZlTWVzc2FnZShldmVudCkgeyBldmVudC5zb3VyY2UucG9zdE1lc3NhZ2UoImhpIHRoZXJlIHlvdXJzZWxmISB0aGUgc2VjcmV0IHJlc3BvbnNlIGlzOiAiICsgZXZlbnQuZGF0YSwgIioiKTsgY29uc29sZS5sb2coIldlIHJlY2VpdmVkIHRoZSBtZXNzYWdlOiAiICsgZXZlbnQuZGF0YSk7IH0gd2luZG93LmFkZEV2ZW50TGlzdGVuZXIoIm1lc3NhZ2UiLCByZWNlaXZlTWVzc2FnZSwgZmFsc2UpOzwvc2NyaXB0Pg==');
function receiveMessage(event)
{
console.log("The message from the data:URI is: " + event.data );
}
function foo()
{
popup.postMessage("The user is 'bob' and the password is 'secret'", "*");
popup.postMessage("hello there!", "*");
}
window.addEventListener("message", receiveMessage, false);
window.setTimeout(foo, 2000);
</script>
<强>参考强>