前端开发-小问题

前端路径

  • 相对路径和绝对路径
    • 相对路径: 相对与某个基准目录的路径;
    • 绝对路径:盘或服务的根目录;

背景

当一个产品存在多端时,通过目录维护;共用一份api,打包时指定

      publicPath: process.env.NODE_ENV === 'production' ? '/client*/' : '/',
  • tips
    - 模拟服务端路径(目录结构),运行 python -m SimpleHTTPServer 1234;
    - 访问: localhost:1234
    - 在network中检查即可;

iframe

iframe中嵌入页面,操作后地址发生变化;但iframe中的src值不会变化;

iframe与父窗口之间的通信;
// 项目iframe传递数据

export const postMessage = (actionType, data) => {
    const msgData = {
        actionType,
        data
    };
    window.parent && window.parent.postMessage(msgData, '*');
};
// iframe中使用
 postMessage(actionType, data);

// 父窗口
React.useEffect(() => {
        const handler = (event: MessageEvent) => {
            if (event.origin === "target url") {
                  /* some  logic*/ 
            }
        };
        window.addEventListener('message', handler, false);
posted @ 2020-08-06 16:47  真我时刻  阅读(106)  评论(0)    收藏  举报
hello world