vue3实现在浏览器之外打开新窗口,新窗口只有原来的一半并且居中显示

首先在router下的index.js添加路由地址

    {
        name: 'attribute',
        path: '/attribute',
        component: () => import('../views/attribute.vue')
    },

然后在方法中调用

//点击按钮
function clicek() {
      openCenteredWindow('/attribute', 1400, 800);
    }
// 计算居中位置
    function calculateCenterPosition(width, height) {
      const screenWidth = window.screen.width;
      const screenHeight = window.screen.height;
      const left = (screenWidth - width) / 2;
      const top = (screenHeight - height) / 2;
      return { left, top };
    }

    // 在新窗口中打开目标页面,居中显示
    function openCenteredWindow(url, width, height) {
      const { left, top } = calculateCenterPosition(width, height);
      window.open(url, '_blank', `width=${width}, height=${height}, left=${left}, top=${top}`);
		//通过这个方式给子页面传递值
      localStorage.setItem('attributeDoneJson', JSON.stringify(globalStore.done_json));
    }
    

然后在新窗口页面中获取数据

function getParentData(){
  const attributeDoneJson = localStorage.getItem('attributeDoneJson');
  if (attributeDoneJson) {
    const doneJson = JSON.parse(attributeDoneJson);
    }

最终打开效果就是这样
在这里插入图片描述

最近更新

  1. TCP协议是安全的吗?

    2024-01-25 06:30:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-25 06:30:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-25 06:30:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-25 06:30:03       20 阅读

热门阅读

  1. 解释LoRA参数

    2024-01-25 06:30:03       36 阅读
  2. nlp文本主题提取算法总结

    2024-01-25 06:30:03       36 阅读
  3. 开源元数据管理平台Amundsen安装

    2024-01-25 06:30:03       40 阅读
  4. #Uniapp:map地图组件

    2024-01-25 06:30:03       32 阅读
  5. tomcat与Apache---一起学习吧之服务器

    2024-01-25 06:30:03       36 阅读
  6. 网络原理——应用层

    2024-01-25 06:30:03       27 阅读
  7. freeswitch中通过嵌入式脚本监听会议事件

    2024-01-25 06:30:03       25 阅读