父頁面:(app.vue)
let _this = this
window.onload = function () {
window.addEventListener('message', function (e) {
let prefix = "openTab:"
if (e.data && (typeof e.data == "string") && e.data.startsWith(prefix)) {
let routerPath = e.data.substring(prefix.length)
_this.$router.push({ path: routerPath });
}
})
}
子頁面:
<script type="text/javascript">
function test(){
let routerPath = "/dashboard"
window.parent.postMessage("openTab:" + routerPath, "*");
}
</script>
<button type="button" onclick="test()">測試</button>